xitas
xitas

Reputation: 1164

Convert Javascript into jQuery ajax?

I am new in jquery and I having trouble in converting my JavaScript into jquery ajax I tried but I did not get it properly if anyone can help me I shall be very thankful to him/her.

how my code works:

When i click on a edit button a popup is displayed showing record of a person and we can edit it in popup and then save it.


This is how it looks like:

enter image description here


This is my JavaScript Ajax code:

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();
} 

Here is my HTML code:

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

Problem: I have tried jquery get method but I can don't know how to call my JavaScript function. and It is showing nothing.

Upvotes: 3

Views: 1559

Answers (2)

Govind Singh
Govind Singh

Reputation: 15490

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

Upvotes: 2

MrCode
MrCode

Reputation: 64526

Using jQuery $.get() would be:

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

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

Upvotes: 2

Related Questions