1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ajax and jQUERY

Discussion in 'jQuery' started by cancer10, Jun 24, 2008.

  1. #1
    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
     
    cancer10, Jun 24, 2008 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
  3. chubaka

    chubaka Greenhorn

    Messages:
    42
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #3
    en.wikipedia.org/wiki/JQuery
     
    chubaka, Jun 26, 2008 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    jquery has a built in component for ajax (and so much more :) )
    go to the jquery site and look at their samples
     
    serialCoder, Jun 26, 2008 IP
  5. websiteideas

    websiteideas Well-Known Member

    Messages:
    1,406
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    130
    #5
    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.
     
    websiteideas, Jun 28, 2008 IP