A newbie asks ajax return values. the ajax return value enters the showmsg function, and alert (tips) returns the value of the function, but it always displays undefined. Is it a type return problem ~
Function showmsg (MS)
{
Var tips
Switch (MS)
{
Case 'Ding ':
Tips = 'Thanx voyun ';
Break
Case 'Cai ':
Tips = 'Thanx u done ';
Break
Case 'erro ':
Tips = '2014 notfound ';
Break;
Default: tips = 'erro ';
Break;
} Return tips;
}
Reply to discussion (solution)
The syntax is incorrect. The first two breaks have missing semicolons and are completed first. Then you can view the error message in the firebug console.
At the function entrance, alert (MS) looks at what was passed in
Js does not require the line terminator ";"
At the function entrance, alert (MS) looks at what was passed in
Js does not require the line terminator ";"
In fact, I saw two more spaces returned by ajax in firebug, but previously I used regular expression to clear it, but there were only two spaces left to clear, and they could not be completely cleared .. The returned value is "1", not "1"
Var str = xmlHttp. responseText;
Var pass = str. replace (/\ r \ n/g ,"");
The syntax is incorrect. The first two breaks have missing semicolons and are completed first. Then you can view the error message in the firebug console.
In fact, I saw two more spaces returned by ajax in firebug, but previously I used regular expression to clear it, but there were only two spaces left to clear, and they could not be completely cleared .. The returned value is "1", not "1"
Var str = xmlHttp. responseText;
Var pass = str. replace (/\ r \ n/g ,"");
Var pass = str. replace (/\ s +/g, ""); this is a clear space, and you have a clear line feed.
Var pass = str. replace (/\ s +/g, ""); this is a clear space, and you have a clear line feed.
You are right ~~ Not clear ~~ Poor at learning