I am trying to send a json RPC ajax request when the page is loaded. Here is my javascript code:
$(document).ready(function() {
var data="orderID=<?=$_POST['orderID'];?>&&lang=eng";
$.ajax({
url: "ajax/get_json_variables.php",
type: "POST",
data: data,
cache: false,
success: function (html) {
var splited=html.split("|");
if(splited[0]=="0")
{
alert(splited[1]);
}
else
{
$.ajax({
url: "https://91.199.226.106/ssljson.php",
type: "POST",
data: splited[1],
cache: false,
dataType:"json",
success: function (html) {
alert(html);
}
});
}
}
});
});
With the first ajax request I get json string for the second request. Google chrome gives me this error:
XMLHttpRequest cannot load https://91.199.226.106/ssljson.php. Origin http://www.nver.am is not allowed by Access-Control-Allow-Origin.
I don`t get what is the problem? Thanks for help.
The issue is due to the Same Domain Policy, and it can be tricky to work around. If you were not using jQuery, a couple of ways you can get around this and still achieve the desired functionality would be to use iframes and a cross-domain messaging helper such as EasyXDM, or dynamically injected tags to fetch your JSON in a special format known as JSONP.
Thankfully you are using jQuery, so you can use http://api.jquery.com/jQuery.getJSON/ and JSONP to work around the Same Origin Policy.