javascript - local AJAX-call to remote site works in Safari but not in other browsers -
i maintaining website uses javascript. script uses jquery , loads content server @ site hosted.
just convenience while maintaining site, run local copy of site on imac. works fine when use safari. firefox, opera , chrome refuse work. guess because of cross-domain-policy. (i couldn't test ie, because ie has run in virtual machine on imac, reason not possible access local files)
is there setting within firefox , other browsers can tell browser ok ajax-load files located on remote server local html-page local javascript?
in nutshell: html-page:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>some title</title> <link rel="stylesheet" type="text/css" href="../css/stylesheet.css"> <script src="../js/jquery-2.1.3.min.js"></script> <script src="../js/myscript.js"></script> </head> <body> <!-- content div-container receive ajax-content --> </body> </html>
this myscript.js:
var errormsg = function (msg) { //insert message html-page }; var jsonerror = function (jqxhr, textstatus, errorthrown ) { var msg = 'json-answer: '+jqxhr.responsetext; msg += '<br>'+'json-errorstatus: '+textstatus; if ($.type(errorthrown) === 'string') { msg += '<br>'+'error: '+errorthrown; } errormsg(msg); }; var jsonreceive = function (jsonobj, statusstring, jqxhr) { //insert data in jsonobj html-page } var startajax = function () { $.ajax({ url: 'http://my.domain.tld/cgi-bin/myperlscript.pl', data: "lastid=" + lastid + '&qkz=' + math.random(), datatype: "json", success: jsonreceive, error: jsonerror }); };
there event-listener, listens page-scroll , resize , checks other constraints (like: there ajax-call in progress?). listener calls startajax
.
when calls startajax
on local copy of page (file:///user/...) within safari, ajax-content fine inserted html-document. within other browsers error-message inserted html-page. is:
json-answer: undefined
json-errorstatus: error
error:
why work in safari not in firefox, chrome , opera?
how can make browsers work?
(i need test browsers, because browsers render same html-domument differently, don't want upload files server after every change test it.)
edit:
after reading answers, want make clear, did not make clear enough:
i searching settings in webbrowsers
- i not change settings of remote webserver (apache)
- i not manipulate files on remote machine (.htaccess)
- i not set webserver on local imac
- i not change code of ajax-calls in javascript-files
- i not change code of perl-scripts on remote server
i can tell why:
i doing short maintainance, , lazy upload every manipulated file remote machine after edited it. settings of webserver fine actual operation. don't want change them (and maybe forget changes before finishing work). same scripts: parts of want change work fine now. there no reason touch ajax-calls, because there nothing wrong them in productive environment.
all want stupid browsers firefox, opera , chrome behave safari , process ajax-calls correctly.
btw:
please can explain risky call data via ajax other domain in firefox, opera or chrome while seems harmless doing same thing in safari?
chrome
there plugin chrome force ignore security policy. can flags. note, please not browse "real web" enabled security risk computer.
firefox
this thread indicates there presently no way in firefox.
opera
again, there not appear built in way ignore cors policies.
the alternative have server (http://my.domain.tld) in case return proper headers - access-control-allow-origin:
Comments
Post a Comment