javascript - XHR Request on Mobile Safari returns nothing -


i'm having issue performing xmlhttprequest in mobile safari (ios 8.3).

var ajax_request = function(){      this.get = function( url, callback ){          var r = new xmlhttprequest();           r.open( 'get', url, true );         r.onload = function (data) {             console.log(data);             if ( r.status >= 200 && r.status < 400 ) {                 callback(r);             } else {                 console.log("an error occured");             }         };         r.onerror = function (err, url, linenumber) {             console.log("a connection error occured");             console.log(err);             console.log(linenumber);         };          r.send();      }  }; 

this code making request asset in shopify.

in browsers have tested, request works fine, in mobile safari, receive empty response.

shopify returns access-control-allow-origin * header set i'm doubtful it's related cors perhaps i'm missing something.

additionally, code has been running on production site time , error has begun occurring makes me think it's either bug in safari update or change in way shopify handles ajax requests.

any light shed on issue hugely appreciated.

desktop safari: (8.0.6)

enter image description here

mobile safari:

screenshot of response in mobile safari

i believe issue shopify not accepting requests using regular http - seemed browser specific.

i fixed issue using https requests , redirected users https version of site if tried access regular one.

it doesn’t explain causing issue, it’s working solution.


Comments