Jashwant
Jashwant

Reputation: 28995

Cross domain / Cross browser , ajax call

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 ?

Upvotes: 1

Views: 1131

Answers (3)

Andres Gallo
Andres Gallo

Reputation: 681

A curl request on the server side should work as well. I'd say try JSONP first, but if it wont work, go for curl request

Upvotes: 0

Ashirvad
Ashirvad

Reputation: 2377

I think you need to go for server side solution. Read the file (i.e index.php) in php and save the required output to be used in a hidden field and on DOM ready You can use the data from that hidden field.

Upvotes: 0

gpojd
gpojd

Reputation: 23055

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...

Upvotes: 1

Related Questions