I am in a hurry to ask a simple ajax question ~ I just learned about ajax and wrote a section ~~ The if (str = "good") in js does not work ~~ If it is returned separately, & nbsp; if it is true that the output is good, it will not work. & nbsp; I don't know why & nbsp; Solution ~ It took me a long time ~~ Anxious !!!! This is a simple ajax question. I am in a hurry ~
I just learned about ajax and wrote a section ~~ The if (str = "good") in js does not work ~~ If the result is returned separately, the output is good.
I can't judge if I put it in. I don't know why ~ It took me a long time ~~ A newbie is in urgent need of advice !!!!
This is html
Untitled Document
Script
Dsds
This is js:
Var xmlHttp;
Function upsdowns (ac, id, ud, mk) //, did)
{
// Obtain the xmlHttpObject object. if it is null, the browser is prompted that ajax is not supported.
XmlHttp = GetXmlHttpObject ();
Var url;
Url = "ajax. php" + "? Ac = "+ escape (ac) +" & url = "+ url +" & id = "+ escape (id) +" & ud = "+ escape (ud) + "& mk =" + escape (mk) + "& sid =" + Math. random ();
// Callback function to execute the action
XmlHttp. onreadystatechange = stateChanged;
// Open
XmlHttp. open ("GET", url, true );
XmlHttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
XmlHttp. send (null );
}
Function stateChanged ()
{
If (xmlHttp. readyState = 4)
{
{If (xmlHttp. status = 200) // phparray = new Array ()
Var str = xmlHttp. responseText;
If (str = "dasda ")
Alert (str );
// Document. getElementById ("txtHint"). innerHTML = str;
}
}
}
// Obtain the xml object
Function GetXmlHttpObject ()
{
Var xmlHttp = null;
Try
{
// Firefox, Opera 8.0 +, Safari
XmlHttp = new XMLHttpRequest ();
}
Catch (e)
{
// Internet Explorer
Try
{
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
}
Return xmlHttp;
}
This is ajax. php
header("Content-type: text/html;charset=utf-8");
header('Vary: Accept-Language');
$w=$_GET['ac'];
$a=$_GET['id'];
$r=$_GET['ud'];;
$t=$_GET['mk'];
if($w!==''&&$a!=''&&$r!==''&&$t!=='')
{echo"good";
}
------ Solution --------------------
Function stateChanged ()
{
If (xmlHttp. readyState = 4)
{
{If (xmlHttp. status = 200) // phparray = new Array ()
Var str = xmlHttp. responseText;
If (str = "dasda ")
Alert (str );
// Document. getElementById ("txtHint"). innerHTML = str;
}
}
}
Wrong place in braces in red. it should be
Function stateChanged ()
{
If (xmlHttp. readyState = 4)
{
If (xmlHttp. status = 200) // phparray = new Array ()