ajax doubt

gijoe
@gijoe-sdsUS3 Oct 26, 2024
<html>
<body>
<script type="text/javascript">
function ajaxfunction()
{
var y=document.myform.na.value;
var z=document.myform.time.value;
var x;
try
{
x=new XMLHttpRequest();
}
catch(e)
{
try
{
x=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
x=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Your browser does not support AJAX :(");
return false;
}
}
}

x.onreadystatechange=function()
{
if(x.readyState==4)
{
document.myform.time.value=x.responseText;
}
}
var url="time.php";
url=url + "?q=" + y ;
url=url + "&sid =" + Math.random();
x.open("GET", url , true);
x.send(null);
}
</script>
<form name="myform">
Name: <input type="text"  name="na"/>
Time: <input type="text" name="time"/>
<input type="button" onclick="ajaxfunction();" name="btn">
</form>
</body>
</html>

this is jus a prog in ajax to check if the username and password are correct???
i jus don get the three lines below:

var url="time.php";
url=url + "?q=" + y ;
url=url + "&sid =" + Math.random();

x.open("GET", url , true);
x.send(null);

how is q assigned the correct value??? of y and wht ll be the variable url while sending??

also i need to attach one more value to the url, it is z here..

in the php code, the stmt
$n=$_GET["q"];
exactly retrieves the value of q and assigns it to n...

so jus say what does that ? and = mean and how they are assigned

thnx in advance

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • sriramchandrk

    @sriramchandrk-wt4rlR Oct 13, 2008

    Hi gijoe,

    This is the line which reads value of name in y
    var y=document.myform.na.value;

    When you click a submit ajaxfunction is called.

    if you write "crazyengineer" in input filed the url formed will be


    #-Link-Snipped-#

    sid will have a random number this is just to take care that each time a new url is produced or else there may be a possibility that browser cache will give old values!

    Thanks & Regards
    Sriram