Question about ajax return values for beginners

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

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.