Why parameter callback from $.post isn't accurate
I create button with many task such as create info and send it via $.post method and I have to check while data is exist in my database and it's succesfull but while I click the previous parameter is still exist, how to set it to be default..
Please, I need help thanks a ton
cek_data();
if(cek == "NOK"){
alert("Exist");
}else{
alert("Data isn't Exist");
}
function cek_data(){
//statement to store url and data开发者_如何学C
$.post( url, data ,
function(data) {
cek= data;
});
}
I use die("NOK") to destination PHP file... and I implement to button on click function...
While I am not too sure what you are asking I will guess. You want to call cek_data() and return a value into cek? I would just use the $.ajax call with async set to false. In the success function set cek=data. dont do cek= cek_data();, just do cek_data();
I can hardly understand your code, but I think you want something like this:
if (update === true) {
$(".name" + id.val()).text(name.val());
operasi_cat = "update";
cat_id = cat_id;
hint = "Data sudah di-Update";
kirim();
} else {
cek_data();
}
function cek_data() {
//statement to store url and data
$.post(url, data, function(data) {
if (cek !== "NOK") {
//statement to append data into div element
kirim();
} else {
//statement to tell data is exist
}
});
}
精彩评论