Monday, 15 September 2014

javascript - AJAX request doesnt get result for some reason -



javascript - AJAX request doesnt get result for some reason -

var id = -1; function addmsg(dataz) { console.log(dataz); } function waitformsg() { console.log("start waitmsg"); $.ajax({ url: "chatxml2.php", type: "post", async: true, cache: false, timeout: 1000, data: {id: id, chat: '.filter_input(input_get,"id").'}, datatype: "xml", done: function(dataz) { //addmsg(nera reikia); addmsg(dataz); console.log("success"); }, fail: function(xmlhttprequest, textstatus, errorthrown){ //addmsg("error", textstatus + " (" + errorthrown + ")"); waitformsg(); console.log("fail"); } }); } $(document).ready(function(){ console.log(id); waitformsg(); });

for reason doesn't result i'm not sure ifim using "data:" right. tried searching while seems cant solve that, i'm quite bad @ js.

php script working 100% correcly, tried html script post.

your syntax wrong. done , fail should success , error respectively.

so should be:

$.ajax({ url: "chatxml2.php", type: "post", async: true, cache: false, timeout: 1000, data: {id: id, chat: '.filter_input(input_get,"id").'}, datatype: "xml", success: function(dataz) { //addmsg(nera reikia); addmsg(dataz); console.log("success"); }, error: function(xmlhttprequest, textstatus, errorthrown){ //addmsg("error", textstatus + " (" + errorthrown + ")"); console.log("fail"); } });

if want utilize deferred syntax be:

$.ajax({ url: "chatxml2.php", type: "post", async: true, cache: false, timeout: 1000, data: {id: id, chat: '.filter_input(input_get,"id").'}, datatype: "xml" }).done(function() { addmsg(dataz); console.log("success"); }).fail(function() { console.log("fail"); });

javascript jquery ajax

No comments:

Post a Comment