Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery AJAX请求未显示在所需的div中_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript Jquery AJAX请求未显示在所需的div中

Javascript Jquery AJAX请求未显示在所需的div中,javascript,jquery,ajax,Javascript,Jquery,Ajax,我似乎对JQUERY有意见 我有一个onclick事件,它调用一个对话框来打开。 打开对话框时,它调用两个函数,这两个函数都是Jquery请求 这两个函数都发送一个成员ID并返回所需的信息,但是只有一个请求显示在div中 这是调用这两个函数的对话框 $("#memberInfo").dialog({ open: function() { getUserCourseInfo(memberid); getUserInfo(member

我似乎对JQUERY有意见

我有一个onclick事件,它调用一个对话框来打开。 打开对话框时,它调用两个函数,这两个函数都是Jquery请求

这两个函数都发送一个成员ID并返回所需的信息,但是只有一个请求显示在div中

这是调用这两个函数的对话框

$("#memberInfo").dialog({
        open: function() {
            getUserCourseInfo(memberid); 
            getUserInfo(memberid); },
        autoOpen: false,
        height: 750,
        width: 610,
        modal: true,
        title: 'Member Information',
        buttons: {
            Close: function() {$(this).dialog( "close" );}},
        close: function() {
            document.getElementById("memberInfoInner").innerHTML="Please Wait...";}
        }); 
这是第一个函数

function getUserInfo(str) //Show the individual user
{
document.getElementById("memberInfoInner").innerHTML="";
if (str=="")
  {
    document.getElementById("memberInfoInner").innerHTML="";
    return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("memberInfoInner").innerHTML=xmlhttp.responseText;
        }
      }
xmlhttp.open("POST","getUser.php");
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("q="+ str);
}
这是第二个函数

function getUserCourseInfo(str1)
{
document.getElementById("Courses").innerHTML="";
if (str1=="")
  {
    document.getElementById("Courses").innerHTML="";
    return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp1=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
    xmlhtt1p=new ActiveXObject("Microsoft.XMLHTTP");
  }
    xmlhttp1.onreadystatechange=function()
      {
      if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
        {
        document.getElementById("Courses").innerHTML=xmlhttp1.responseText;
        }
      }
xmlhttp.open("POST","getUserCourseInfo.php");
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("q="+ str1);
}
代码后面正确定义了div。 任何人能给予的任何帮助都将是伟大的

谢谢


理查德

我要暗中试探一下,说这可能是你的问题:

function getUserCourseInfo(str1)
{
document.getElementById("Courses").innerHTML="";
if (str1=="")
  {
    document.getElementById("Courses").innerHTML="";
    return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp1=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
    xmlhtt1p=new ActiveXObject("Microsoft.XMLHTTP");
  }
    xmlhttp1.onreadystatechange=function()
      {
      if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
        {
        document.getElementById("Courses").innerHTML=xmlhttp1.responseText;
        }
      }
xmlhttp.open("POST","getUserCourseInfo.php");
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("q="+ str1);
}

请注意,最后三行引用的是
xmlhttp
,而函数的其余部分引用的是
xmlhttp1

,我将在黑暗中试探一下,并说这可能是您的问题:

function getUserCourseInfo(str1)
{
document.getElementById("Courses").innerHTML="";
if (str1=="")
  {
    document.getElementById("Courses").innerHTML="";
    return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp1=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
    xmlhtt1p=new ActiveXObject("Microsoft.XMLHTTP");
  }
    xmlhttp1.onreadystatechange=function()
      {
      if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
        {
        document.getElementById("Courses").innerHTML=xmlhttp1.responseText;
        }
      }
xmlhttp.open("POST","getUserCourseInfo.php");
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("q="+ str1);
}
请注意,最后三行引用了
xmlhttp
,而函数的其余部分则引用了
xmlhttp1

使用jQuery ajax()…省去了所有这些麻烦和额外的代码

但是:
xmlhtt1p
是错误的,第二个函数中的其他引用也是错误的。(这是您真正的问题)

还有(不是问题的一部分,但…) 为什么:

什么时候

是一样的吗

编辑:注意:xmlhttp、xmlhttp1、xmlhtt1p都是全局引用,这是有意的吗?如果是这样的话,ajax调用的异步特性可能会妨碍您。

使用jQuery ajax()…省去所有这些麻烦和额外的代码

但是:
xmlhtt1p
是错误的,第二个函数中的其他引用也是错误的。(这是您真正的问题)

还有(不是问题的一部分,但…) 为什么:

什么时候

是一样的吗


编辑:注意:xmlhttp、xmlhttp1、xmlhtt1p都是全局引用,这是有意的吗?如果是这样的话,ajax调用的异步特性可能会妨碍您的工作。

这些函数根本不使用jQuery,它们是简单的老Javascript ajax调用。您看到哪些功能不正确?其中一个调用是否导致没有输出或输出位置错误?这两者之间有着巨大的差异。另外,为divs发布你的HTML——你的词定义正确真的不足以保证。我不明白你没有使用jQuery的AJAX库,而你已经在使用jQuery了。。。这将使事情变得更容易。还有一件事——哪些请求(函数)按预期工作,哪些是不正确的?知道他们中的哪一个是错的将有助于缩小范围,并希望能更快地给你一个答案。使用jQuery提供的Ajax函数重构它(因为您已经在使用jQuery),您的生活将大大简化。有些人不惜一切代价避免使用框架,但由于您已经在使用它,jQuery的Ajax函数是它最好的功能之一。其他人是正确的,使用jQuery
Ajax()
,但是
xmlhtt1p
是错误的。这些函数根本不使用jQuery,它们是简单的老Javascript Ajax调用。您看到哪些功能不正确?其中一个调用是否导致没有输出或输出位置错误?这两者之间有着巨大的差异。另外,为divs发布你的HTML——你的词定义正确真的不足以保证。我不明白你没有使用jQuery的AJAX库,而你已经在使用jQuery了。。。这将使事情变得更容易。还有一件事——哪些请求(函数)按预期工作,哪些是不正确的?知道他们中的哪一个是错的将有助于缩小范围,并希望能更快地给你一个答案。使用jQuery提供的Ajax函数重构它(因为您已经在使用jQuery),您的生活将大大简化。有些人不惜一切代价避免使用框架,但由于您已经在使用它,jQuery的Ajax功能是它最好的功能之一。其他人是正确的,请使用jQuery
Ajax()
,但是
xmlhtt1p
是错误的。谢谢。我不敢相信我居然错过了最后三行。再次感谢,谢谢。我不敢相信我居然错过了最后三行。再次感谢Rich
document.getElementById("Courses").innerHTML="";
if (str1=="") {
   return;
}