Here’s the scenario,
I have a main.js file in abc.com which does $.post("index.php") to access contents from the index.php from the same domain (abc.com).
This works great, as it is same domain ajax call.
But now, anyone can inlucde main.js in their website (say domain xyz.com).
Now, the path index.php (in $.post("index.php")) refers to file in domain xyz.com (not abc.com). If I put an absolute path http://www.abc.com/index.php , this does not work in some browsers (cross domain ajax restriction)
Now,
If I put headers for allow cross domain in php file, it does not work either, fails in ie 7 and below.
p.s. I need to put content in index.php file ( not in main.js ). Also, I dont want to include a php file
<script type='text/javascript' src='http://abc.com/index.php'></script>
and I would prefer not to add .js file to treat as php file in server ( so I can put php code in js file ).
The content is huge, I cannot do get request or jsonp (I think, jsonp does not allow large data)
Am I missing something ? How can I achieve this ?
You can use either JSONP or CORS to achieve this.
I’ve used JSONP and am going to try CORS next week. I think CORS is still asyncronous, so that might have the edge for me. At least that’s my hope…