The Ajax request data in the js Method is judged and the verification is invalid (OnClientClick = & amp; quot; return Method (); & amp; quot;), or the background code is directly executed.

Source: Internet
Author: User

The Ajax request data in the js Method is judged and the verification is invalid (OnClientClick = & quot; return Method (); & quot;), or the background code is directly executed.

Function CheckAdd () {var flag = true; $. ajax ({cache: false, async: false, url: "/ajaxpage/getajax. aspx? T = adjserviceclientlist & Cellphone = "+ Cellphone +" & a = "+ Math. random (), ype: 'json', success: function (data) {if (data! = Null) {var result = data ["Remark"]; if (result = 'This number already exists and has been bound to the master number. It cannot be bound again! ') {Alert (result); flag = false;} if (result =' This number already exists. Are you sure you want to bind it to the primary number? ') {If (confirm (' This number already exists. Are you sure you want to bind it to the primary number? ') {$ (' # MainContent_Hiddend_IsExitCellPhone '). val ('1') ;}else {flag = false ;}}}) if (! Flag) {return false ;}}


 


Problem 1: ajax is asynchronous by default. Therefore, when ajax is executed, the background method is also executed. For example:

Async: "false" indicates synchronization.


Question 2: make a judgment on the data returned by the ajax request. The return false operation cannot be performed directly. A value must be assigned and executed outside the request method. For example:

If (! Flag ){
Return false;
}




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.