javascript - Ajax callback called mulitple times -



javascript - Ajax callback called mulitple times -

i have ajax-call script searching numbers. respons json array name , surname(strings). client-script , think dont see why script looping , sending respons multiple times. toogle-solution lastly thing tried.

$(document).ready(function () { $("#phone").keyup(function () { var number = $(this).val(); var toogle = 0; if (number.length == 10 && toogle == 0) { alert('inside 10 numbers'); toogle = 1; $.ajax({ type: "post", url: "info-phone.php", datatype: "jsonp", data: { number: number } }).done(function (msg) { toogle = 0; if (msg.name != "" && msg.surname != "") { $("#phone").add("are " + msg.name + " " + msg.surname); }; }); //done-function } }); //phone-keyup }); //document-ready

basicly have input, , when user reaches 10 numbers script phone call server , name number.

any ideas? typo?

try this:

$(document).ready(function () { window.toogle = 0; $("#phone").click(function () { var number = $(this).val(); if (number.length == 10 && window.toogle == 0) { alert('inside 10 numbers'); window.toogle = 1; $.ajax({ type: "post", url: "info-phone.php", datatype: "jsonp", data: { number: number } }).done(function (msg) { window.toogle = 0; if (msg.name != "" && msg.surname != "") { $("#phone").add("are " + msg.name + " " + msg.surname); } }); //done-function } }); //phone-keyup }); //document-ready

javascript jquery ajax

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -