SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX & this javascript code

    Hello firends



    From:
    http://www.w3schools.com/ajax/ajax_database.asp


    The AJAX JavaScript




    This is the JavaScript code stored in the file "selectcustomer.js":

    var xmlHttp

    function showCustomer(str)
    {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request")
    return
    }
    var url="getcustomer.asp"
    url=url+"?q="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }

    function stateChanged()
    {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    document.getElementById("txtHint").innerHTML=xmlHttp.responseText
    }
    }

    function GetXmlHttpObject()
    {
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
    objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
    }








    May you explain about this line?

    url=url+"&sid="+Math.random()

    Why does it create sid?
    If we use PHP,Must I do that also?


    Thanks in advance.
    I shall build a boat,I shall cast it in the water,
    I shall sail away from this strange earth,
    Where no one awaken the heroes in the wood of love

  2. #2
    SitePoint Zealot bensheard's Avatar
    Join Date
    Jun 2006
    Location
    Cape Town | South Africa
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One possibility is that sid is session ID. And then they assign a random number to this.
    Ben Sheard
    -------------
    Log all your dives easily and quickly from anywhere in the world
    www.divinglogs.cafe150.com

  3. #3
    SitePoint Enthusiast tarunkrsna's Avatar
    Join Date
    Dec 2005
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am a student of web design in Australia. We are very busy. I would love to get to know more about ajax but .. no time. However, I did learn a bit about using it from Eddie Traversa

    http://dhtmlnirvana.com/program/perm...tutorial1.html

    I actually got it working and edited it to display what I wanted (just a trial run) to see how it worked. No big traumas. You can download all the files from Eddie and play around with them on your local server to get a feel for it.

    http://www.sevamrta.com/tafe/steve_s..._edit_trials/#

    I would like to comment that the sid is the state ID BUT I'm guessing and then I have no idea why the statement includes the math random function.

    Sitepoint also have a tutorial on ajax and also a book.

    cheeeeeeeeeers.t3rry();

  4. #4
    SitePoint Zealot yacka's Avatar
    Join Date
    Aug 2006
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My guess is the sid parameter is a cache buster. Be aware that in their example the str parameter is being supplied directly to a query making the resulting page vulnerable to a sql injection attack.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •