I am using this jQuery.ajax:
var url = "http://client.my_url.com/test_get_account_data.php";
jQuery.ajax({
type: "GET",
url: url,
cache: false,
success: function(resultsData){
alert("We're finally making the call.");
},
error:function (jqXHR, textStatus, errorThrown){
alert("Error:" + textStatus+ "," + errorThrown);
}
});
To hit this php script:
<?php
header("Content-Type: text/plain");
$myFile = "LogFile.log";
$fh = fopen($myFile, 'w');
$accountJSON = array("id"=>"Level 3.accountName","type"=>"Level 3","name"=>"accountName","total"=>"1059.25","in"=>"8603.56","out"=>"7544.31");
$encodedResponse = json_encode($accountJSON);
fwrite($fh, "We're at the end of get_account_data with encodedResponse:\n");
fwrite($fh, $encodedResponse."\n");
echo $encodedResponse;
?>
But for some reason, I never get a success. I’ve simplified this as much as I can imagine, but it still fails. In the log, I have the output:
We're at the end of get_account_data with encodedResponse:<br/>
{"id":"Level 3.accountName", "type":"Level 3", "name":"accountName", "total":"1059.25", "in":"8603.56", "out":"7544.31"}
Does anyone have any suggestions? I would think this would be very easy… and maybe it is and I’m just doing something stupid.
Thanks
It seems you are trying to call
http://client.my_url.comwith AJAX GET request fromhttp://localhost:8080According to same origin policy of browsers you cannot send AJAX GET/POST requests to another domain. You need to use JSONP for cross domain AJAX.