javascript - Ajax not working in firefox without alert -
function processajaxstatechangeforrowadd() { alert(0); if (req.readystate == 4) { // complete if (req.status == 200) { // ok response processforrowadd(req.responsetext); } else { alert("problem: " + req.statustext); } } }
this code working fine ie, safari , firefox, if remove alert
, code not work in firefox, though still works in ie , safari.
can give me suggestion why not working in firefox without alert?
edit: code adds row:
if (window.xmlhttprequest && browserversion.indexof("microsoft") == -1 ) { // code firefox, chrome, opera, safari req = new xmlhttprequest(""); if (req) { ajaxprocessed = false; req.onreadystatechange = processajaxstatechangeforrowadd; req.open("post", url, true); req.send(); // alert("1"); } }
the alert
blocking. means script temporarily suspended (even if it's few milliseconds). during time, ajax request completes , req
object being set. can add delay (using settimeout) callback verify this.
i suggest post more of script can set callback properly. alternatively, use library such jquery set ajax calls in cross-browser manner easily.
edit: need either declare req
global variable, or use anonymous function. following code demonstrates first method (using global variable):
var req; if (window.xmlhttprequest) { req = new xmlhttprequest(); if (req) { req.onreadystatechange = processajaxstatechangeforrowadd; req.open("post", url, true); req.send(); } } function processajaxstatechangeforrowadd() { if (req.readystate == 4) { // complete if (req.status == 200) { // ok response processforrowadd(req.responsetext); } else { alert("problem: " + req.statustext); } } }
Comments
Post a Comment