php - ajax http request status returning zero on mobile browsers only -


i have been using code long time successfully:

function doxmlreq(url, data) {     var req = false;     if (window.xmlhttprequest) {          req = new xmlhttprequest();         if (req.overridemimetype) {             req.overridemimetype('text/xml');         }     }     req.onreadystatechange = function() { dostuff(req); };     req.open('post', url, true);     req.setrequestheader('content-type', 'application/x-www-form-urlencoded');     req.setrequestheader('content-length', data.length);     req.setrequestheader('connection', 'close');     req.send(data); }  function dostuff(req) {     if (req.readystate == 4) {         alert(req.status);         if (req.status == 200) {             alert('ok');         }     } } 

the url submits post php script returns xml. added in these alerts simple testing. alerts major functionality placed, , on every desktop browser reach "ok" alert after submitting form. additionally, if console.log(xml) type statements issued, can see xml loaded on desktop browser, , functionality normal.

for reason on mobile browsers (safari, android) req.status alert has value of 0, , xml data not returned. if post form directly url (instead of using js), browser renders xml perfectly.

the url in same directory original php file, on same domain, etc. header set correctly on php form passed through url.

header('content-type: text/xml'); 

i thinking may have https, since page encounters error, , page in https domain out of maybe hundred pages code on.

i have tried use jquery's $.ajax, because many other users in other threads have suggested use of jquery solve cross-browser woes. re-wrote entire php script , of javascript accomidate $.ajax , must admit reduced code meaningful amount, xml http request still returns 0 on mobile browsers... here code used:

function doform() {     var form = $('#i_form');     $.ajax({             type: form.attr("method") || 'post',             url: "fooscript.php",             data: form.serialize(),             datatype: 'xml', //disables xml autoparsing             success: function(xml){                     doxmlback(xml);             },             error: function(jqxhr, textstatus, errorthrown) {                     alert(jqxhr.status);                     alert(jqxhr.statustext);             }     });     return false;  }  function doxmlback(xml) {     var errors = $(xml).find("errors").text();     var success = $(xml).find("uri").text();     if (errors) {         errmsg = errors.split("|");         errmsg = errmsg[1];         $('#er').text(errmsg);         return false;     }     if (success) {         window.location = success;     } }  

(obviously above instead of form being submitted there div has simple onclick function calls doform() function)...

how can mobile browsers running on 3g/4g submit form , receive xml data using ajax?


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -