簡體   English   中英

將Javascript轉換為jQuery ajax?

[英]Convert Javascript into jQuery ajax?

我是jquery的新手,我在將JavaScript轉換為jquery ajax方面遇到了麻煩,但是如果有人能幫助我的話,我沒有得到它,我將非常感謝他/她。

我的代碼如何工作:

當我點擊編輯按鈕時,會顯示一個彈出窗口,顯示一個人的記錄,我們可以在彈出窗口中編輯它然后保存它。


這是它的樣子:

在此輸入圖像描述


這是我的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();
} 

這是我的HTML代碼:

<div id="dialog" title="Edit">
<div id="txtHint"></div>
</div>

問題:我嘗試過jquery get方法,但我不知道如何調用我的JavaScript函數。 它什么都沒有顯示出來。

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

使用jQuery $.get()將是:

function update(str)
{
  if (str=="") {
    $("#txtHint").html("");
    return;
  }

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM