View Full Version : Ajax and jQUERY

06-25-2008, 07:33 AM

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.open("GET", "search.php?keyword="+ strkeyword +"&domain=" + strdomain + "&engine=" + strengine, true);
http.onreadystatechange=function() {

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.


06-25-2008, 11:49 AM
Did you look under the 'ajax' (http://docs.jquery.com/Ajax) topic in the documentation?

The basics of a get would be



$.get( "search.php?keyword="+ strkeyword +"&domain=" + strdomain + "&engine=" + strengine, function(){});

You could also write it as :

$.get("search.php", {keyword:strkeyword,domain:strdomain,engine:strengine});

06-25-2008, 12:04 PM
OK i got that but how do I display the search results via jquery?

with normal Ajax function, it would be something like

document.getElementById('foo').innerHTML = http.responseText;

<div id="foo">Your results will be displayed here</div>

06-25-2008, 12:41 PM
$.get("search.php", {keyword:strkeyword,domain:strdomain,engine:strengine}, function(data)

06-25-2008, 12:42 PM
you can also do:

$('#foo').load("search.php?keyword="+ strkeyword +"&domain=" + strdomain + "&engine=" + strengine);

if you just want the result of an ajax query to load into a div.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum