I have my JavaScript files in my main domain, and I want to make some calls from a subdomain.
I added:
url: "http://domain.com/ajax.php"
So the full code:
$.ajax({ type: "POST", url: "http://domain.com/ajax.php", data: { var1: var1, var2: var2 }, success: function(data){ } });
But in Firebug, it shows the request as red , and it does not respond. POST parameters are also where they should be.
Should I create a new JS file on a subdomain and add the necessary codes and call AJAX from there?
EDIT: using JSONP code
I use this on localhost/ajax.php , which I call from sub.localhost
$.ajax({ dataType: 'jsonp', data: 'id=10', jsonp: 'jsonp_callback', url: 'http://localhost/ajax.php', success: function (data) { console.log(data); }, });
and ajax.php contains:
<?php echo $_GET["id"]; ?>
source share