Hi, I am trying to learn ajax with jquery. The following code is a simple ajax script that sends the values for 3 fields to another page search.php. <script type="text/javascript"> var http = false; if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); } var strkeyword= document.forms['myform'].txtKeyword.value; var strdomain= document.forms['myform'].txtDomain.value; var strengine = document.forms['myform'].txtEngine.value; http.abort(); http.open("GET", "search.php?keyword="+ strkeyword +"&domain=" + strdomain + "&engine=" + strengine, true); http.onreadystatechange=function() { </script> Code (markup): Now question: Can this script be written in jQUERY? if yes how? I search on the jquery site but could not find anything that can help me. Thanx
jquery has a built in component for ajax (and so much more ) go to the jquery site and look at their samples
So, it would look something like this in jQuery: $.get("search.php?keyword="+ strkeyword +"&domain=" + strdomain + "&engine=" + strengine", function(data){ //console.log("Data Returned: " + data); }); Put that in the on ready function that jQuery provides. The console.log is not required, but it can be useful to return something from this AJAX call and jQuery makes that easy with a callback.