I am in a hurry to ask a simple ajax-related question.

Source: Internet
Author: User
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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.