The question of the novice asking for the Ajax return value

Source: Internet
Author: User
The Ajax return value enters the ShowMsg function, and then alert (tips) out of the value returned by the function, but the total display of undefined, is not the question of return type, novice ask ~
function ShowMsg (MS)
{
var tips
Switch (MS)
{
Case ' ding ':
tips= ' thanx votting ';
Break
Case ' Cai ':
Tips= ' thanx u done ';
Break
Case ' Erro ':
tips= ' 404 NotFound ';
Break
default:tips= ' Erro ';
Break

}return tips;
}


Reply to discussion (solution)

Syntax error, the previous two break missing the ending semicolon, first filled. Then read the newspaper under the Firebug console what's wrong.

Alert (MS) at the entrance of the function to see what's coming in

JS does not enforce the need for line Terminator ";"

Alert (MS) at the entrance of the function to see what's coming in

JS does not enforce the need for line Terminator ";"
In fact, I see in the Firebug Ajax returned more than 2 spaces, but the front I use regular expression is cleared, but the remaining two empty Ge Qing, can not be completely cleared. The return is "1", not "1".
var Str=xmlhttp.responsetext;
var pass= str.replace (/\r\n/g, "");

Syntax error, the previous two break missing the ending semicolon, first filled. Then read the newspaper under the Firebug console what's wrong.

In fact, I see in the Firebug Ajax returned more than 2 spaces, but the front I use regular expression is cleared, but the remaining two empty Ge Qing, can not be completely cleared. The return is "1", not "1".
var Str=xmlhttp.responsetext;
var pass= str.replace (/\r\n/g, "");

var pass= str.replace (/\s+/g, ""); This is the clear space, your that is clear change line

var pass= str.replace (/\s+/g, ""); This is the clear space, your that is clear change line
You are right to say ~ ~ didn't learn well

  • 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.