3

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.

3
  • Could you share with us the code where you tried to use jQuery.get method? Commented Apr 14, 2014 at 11:56
  • Please share what you tried using jquery ajax Commented Apr 14, 2014 at 11:58
  • I did share it cause I don't think that would be useful. Commented Apr 14, 2014 at 12:09

2 Answers 2

2

Using jQuery $.get() would be:

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

  $.get('updateattendence.php', { q : str }, function(response){
    $('#dialog')
      .html(response)
      .dialog();
  });
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank you sir this code worked fine but what you suggest me whether i use get method of jquery ajax or and ajax method of jquery ajax.
$.get() is just a shortcut for $.ajax with limited options so if don't need all the options that the latter provides then the former is fine. It also depends on personal preference, some people just use $.ajax exclusively and don't bother with the shortcuts $.get(), $.post() etc.
2
function update(str)
{
if (str=="")
  {
  $("#txtHint").html("");
  return;
  } 
 $.ajax({
        type : "GET",
        url : "/updateattendence.php?q="+str,
        success : function(responseText) {
        $("#dialog").html(responseText);
        $( "#dialog" ).dialog();
        }
       });
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.