Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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?_Javascript_Jquery_Html_Ajax - Fatal编程技术网

将Javascript转换为jQuery ajax?

将Javascript转换为jQuery ajax?,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我是jquery新手,在将JavaScript转换为jQueryAjax时遇到了麻烦,我尝试过,但没有正确地获得它。如果有人能帮助我,我将非常感谢他/她 我的代码如何工作: 当我点击编辑按钮时,弹出窗口显示一个人的记录,我们可以在弹出窗口中编辑它,然后保存它 这就是它的样子: 这是我的JavaScript Ajax代码: function update(str) { if (str=="") { document.getElementById("txtHint").innerHTM

我是jquery新手,在将JavaScript转换为jQueryAjax时遇到了麻烦,我尝试过,但没有正确地获得它。如果有人能帮助我,我将非常感谢他/她

我的代码如何工作:

当我点击编辑按钮时,弹出窗口显示一个人的记录,我们可以在弹出窗口中编辑它,然后保存它


这就是它的样子:


这是我的JavaScript Ajax代码:

function update(str)
{
if (str=="")
  {
  document.getElementById("txtHint").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("dialog").innerHTML=xmlhttp.responseText;
       $( "#dialog" ).dialog();
    }
  }
xmlhttp.open("GET","updateattendence.php?q="+str,true);
xmlhttp.send();
} 
<div id="dialog" title="Edit">
<div id="txtHint"></div>
</div>
这是我的HTML代码:

function update(str)
{
if (str=="")
  {
  document.getElementById("txtHint").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("dialog").innerHTML=xmlhttp.responseText;
       $( "#dialog" ).dialog();
    }
  }
xmlhttp.open("GET","updateattendence.php?q="+str,true);
xmlhttp.send();
} 
<div id="dialog" title="Edit">
<div id="txtHint"></div>
</div>

问题: 我尝试了jqueryget方法,但我不知道如何调用我的JavaScript函数。它什么也没表现出来

使用jQuery将是:

function update(str)
{
if (str=="")
  {
  $("#txtHint").html("");
  return;
  } 
 $.ajax({
        type : "GET",
        url : "/updateattendence.php?q="+str,
        success : function(responseText) {
        $("#dialog").html(responseText);
        $( "#dialog" ).dialog();
        }
       });
} 
function update(str)
{
  if (str=="") {
    $("#txtHint").html("");
    return;
  }

  $.get('updateattendence.php', { q : str }, function(response){
    $('#dialog')
      .html(response)
      .dialog();
  });
}

您能与我们分享您尝试使用jQuery.get方法的代码吗?请分享您尝试使用jQuery的代码。ajaxI确实分享了它,因为我认为这不会有用。谢谢先生,这段代码工作得很好,但您建议我使用jQuery ajax的get方法还是jQuery ajax的ajax方法。
$.get()
只是
$的快捷方式。ajax
具有有限的选项,因此如果不需要后者提供的所有选项,那么前者就可以了。它还取决于个人偏好,有些人只使用
$.ajax
,而不使用快捷方式
$.get()
$.post()
等。