Home > Web Front-end > JS Tutorial > How to set up synchronization when executing the ajax function in jquery_jquery

How to set up synchronization when executing the ajax function in jquery_jquery

WBOY
Release: 2016-05-16 16:57:48
Original
949 people have browsed it

JavaScript code

Copy code The code is as follows:

function existProduct(obj){

var productname = escape(obj.val());
$.getJSON("../product/searchProductByName.action",datat,function(data){
var falg;
falg = data[0]['existproduct'];
//falg returns no or yes,
return falg;
});

}

function validateform( ){
//alert(existProduct($("#products_name")));
if(validateNotnull($("#products_name"))){
if(existProduct($("#products_name "))){
$("#productform").submit();
}else{
$("#spanproduct").html("Business name already exists");
}
}else{
$("#spanproduct").html("Business name cannot be empty");
}
}

In this existProduct( obj) In this function, I call the getJSON function in jquery to return the search results in the database. I checked this with firebug and there should be no problem. What is outrageous is that during execution, the code executes return falg first, and then executes getJSON. Please give some advice from experts
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template