1

Hi, 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 mins. if it finds it then does nothing. else alerts me.

The problem i'm facing is : I can't seem to use either POST/GET from the local htm 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/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.. (?)

Do you know any workaround?

flag

3 Answers

1

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: "Ajax get an XML file", in which the answers describe some possible workarounds.

link|flag
The question mentions that the file is local, so it's an origin problem. – Max Shawabkeh Feb 11 at 12:53
Thanks brother. – DMin Feb 11 at 14:43
I finally solved it using my local wamp server. I made a local php script that would get the data i need using a cURL and a javascript that called the php script. – DMin Feb 22 at 23:44
0

Same Domain Origin Policy. One workaround is to write a server side script hosted on the same domain and serving as a proxy to the distant domain. IMHO using pure javascript it is impossible to achieve.

link|flag
Or you could make it a browser extension - those can declare their own permissions, and don't need much extra code. – Max Shawabkeh Feb 11 at 12:46
0

If you're trying to get data from a different domain you'll need to use JSONP to receive it.

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.