Ajax post submits data, input type = submit returns prompt aborted by user

Source: Internet
Author: User

 

When Ajax post is submitted, it returns normally but reports:

 

[16:33:22. 879] uncaught exception: [exception... "prompt aborted by user" nsresult: "0x80040111 (ns_error_not_available)" Location: "JS frame: Resource: // components/nsprompter. JS: opentabprompt: Line 462 "data: No]

This error message is displayed when you use firebug to view it,

 

This problem mainly occurs when the form is submitted using post and when the form is submitted using type = submit, if you want to do something inside the callback function, especially when you want to output HTML Div on the page, the situation is different.

 

Type = sumbit

 

Is a normal submission, from the initiate request to the Response Return to the page, that is, return to the form for a complete request, that is, the request must return to the page where the form is initiated, A complete request

 

Type = post

 

The complete Request Path and response for jquery POST requests are the same as above, but now we want to do something inside the callback function, therefore, the end of response cannot be the page (the page where the form is initiated). Instead, you should use the (return false statement) to intercept the jquery Ajax request.

 

Code:

<SCRIPT type = "text/JavaScript">
VaR XMLHTTP = NULL;

// Create XMLHttpRequest;
Function Init (){

If (window. XMLHttpRequest) {// Mozilla Browser
XMLHTTP = new XMLHttpRequest ();
Alert ("XMLHttpRequest ")
}
Else if (window. activexobject) {// IE browser
Try {
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
Alert ("msxml2.xmlhttp ")
} Catch (e ){
Try {
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
Alert ("Microsoft. XMLHTTP ")
} Catch (e) {alert ("" ")}
}
}

}
// Callback function
Function callback (){

If (XMLHTTP. readystate = 4 ){

If (XMLHTTP. Status = 200 ){

Alert (XMLHTTP. readystate );
Alert (XMLHTTP. responsetext );
}

}

}
Function processuser (){
Alert ("processuser ");
VaR inputoneobj = Document. getelementbyid ('input _ user ');
VaR inputtwoobj = Document. getelementbyid ('input _ cadno ');
VaR inputthrobj = Document. getelementbyid ('input _ pa ');
VaR name = inputoneobj. value;
VaR id = inputtwoobj. value;
VaR PASD = inputthrobj. value;
// Alert (opername );
Init ();
XMLHTTP. onreadystatechange = callback;
VaR post = "username =" + name + "& cardno =" + ID + "& Password =" + PASD;

// Servlet's solution to accepting garbled Chinese characters must be encoded (twice ).
Post = encodeuri (post );
Post = encodeuri (post );
VaR url = "guashisevlet ";
// Send the request to the URL address in post mode. True indicates asynchronous mode, and false indicates synchronous mode.

XMLHTTP. Open ("Post", URL, true );
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send (post );

}
Function checkuser (){
VaR input_obj1 = Document. getelementbyid ('input _ user ');
VaR input_obj2 = Document. getelementbyid ('input _ cadno ');
VaR input_obj3 = Document. getelementbyid ('input _ pa ');
VaR user_name = input_obj1.value;
VaR user_cadno = input_obj2.value;
VaR user_pas = input_obj3.value;
If (user_name = ""){
Alert ("the user name cannot be blank! ");
Return false;
}
If (user_cadno = ""){
Alert ("the card number cannot be blank! ");
Return false;
}

If (user_pas = ""){
Alert ("the password cannot be blank! ");
Return false;
}
Else {
Processuser ();

// Do not reduce the number. Otherwise, a prompt aborted by user exception will be reported.
Return false;
}

}
</SCRIPT>

Related Article

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.