I have the form with text area.In the text area user can enter keywords per line.
I want to do like this. After click the button send ajax request to the server and get result of the first keyword.Then display/append it.After that finished send second ajax request for 2nd keyword.Like this for per each keyword.
I want to do this because of server response is little slow per keyword.If display all keyword output at once that is getting too many time to see the result. So in above method I think user no need to wait for see the all results.User can see one by one keyword output.
My code is like this and I'm using this in the wordpress plugin.Get result as json.
jQuery(document).ready(function () {
jQuery('#get_seo_rank').click(function() {
var keywordLines = jQuery('#keywords').val().split(/\n/);
var current = 0;
var total = keywordLines.length;
for (var i=0; i < total; i++) {
jQuery.ajax({
type : "post",
dataType : "json",
url : process.php,
data : {
action: "get_rank",
keywords: keywordLines[i]
},
beforeSend:function(){
},
success:function(response){
if(response.type == "success") {
jQuery("#resultWrap").append(response.result);
}
else if(response.type == "error") {
jQuery("#resultWrap").html(response.result);
} else {
jQuery("#resultWrap").html(response.result);
}
},
error:function(response){
}
});
} // end loop
}); // end click event
});
If anyone can help regarding this that would really appreciate.
Thank you very much !