I’m just making a small utility with a local HTML file (checker.htm) with JavaScript (using jQuery) on my desktop that requests data from my website every 10 minutes. If it finds it then it does nothing, else it alerts me.
The problem I’m facing is: I can’t seem to use either POST or GET from the local HTML file c:\checker.htm:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$.post("http://www.mysite.com/st/prod_json.php?products_id=15",{},function(data){alert(data);},"text");
});
</script>
I’ve tried using POST or GET and with the options: “text”/”json” — all with the same result: Only a blank popup.
My best guess, is this a JavaScript permission issue?
Is there any workaround?
You have to use a relative URL for
$.post(). Otherwise the browsers will refuse to make the Ajax request in order to prevent cross-site scripting.There was a related question earlier today: “Get an XML file using Ajax“, in which the answers describe some possible workarounds.