// Verify supplier $ ("# Providerid"). ATTR ("value ",""); // Clear $. Ajax ({URL: '$ {Path}/product/findbyproviderid' , Async: False , // Synchronization Type: 'post' , Data: {qc_provider_name: $ ( "# Qc_provider_name"). Val ()}, datatype: 'Text' , Success: Function (Result) {$ ( "# Providerid" ). Val (result );}}); If ($ ("# Providerid"). Val () = "" ) {Alert ( "The supplier does not exist" ); Return False ;}
Upper sectionCodeIs a part of JS. Previously, Ajax's async: false was not added. If not,ProgramAjax is asynchronous by default, that is, the two pieces of code do not affect each other. Then, a dialog box is always displayed, indicating that the supplier does not exist. I said it is strange. In the success attribute, the result value is displayed, there is a value, and then a javascript variable is set to accept the value of result, there is a value in it, not outside, get a hidden input accept value is also a value in the execution, there is no value outside. I checked it and did not add a synchronization ID.
Ajax is asynchronous by default, that is, when the above code is executed, the following code is also executed at the same time, and the above result code is still being executed, the code for the variable assigned by the result value is also being executed. Of course, it is empty. After the synchronization identifier is added, the code is executed in sequence and OK. Previously, it was used in that way and never thought about synchronous and asynchronous. Note: