views:

40

answers:

2

Hello there,

I'm working on a little widget that will allow to embed like an iframe (but with a jQuery plugin) a part of my website.

I've successfully made a search.php API that produces in JSONP what I need to retrieve. It works! (thx to this community ;) ). I had difficulties to understand and use right callback request to allow a distant server to retrieve info on mine.

Now, I'd like to do the other way of interracting: writting :ask a question, vote for an answer.. I've made pages that accept GET parameters to do that.

For example, if I call myserver.php/vote.php?id_vote=xxx I add a vote to the answer xxx in my database, and return 1 ok status. But it appears to work not as easily as if I were on my server..

How can I call this vote.php page on another server, using jQuery and $.Get or $.ajax?

Thanks a lot

+1  A: 

You can perform your Ajax call on a php page which contain

echo file_get_contents('url');

But you need to have allow_url_fopen activated.

MatTheCat
I'm not sure to understand: I place the line file_get_contents('url'); at the beginning of my vote.php or I make a intermediary file like temp_vote.php with this line, that refers to vote.php?
CoBaLt2760
Second solution (intermediary file), it's the best way I found to avoid Same Origin Policy.
MatTheCat
Ok then, how to pass my GET arguments with this method? file_get_contents('vote.php?id_vote=xxx'); will it work? Thx again
CoBaLt2760
Can't you test ?? Yes it will work, no problem for GET parameters.
MatTheCat
Ok, thanks for your answer. I'm sorry for all that questions, I'm not admin on the distant server, and it takes time and process to me to make things done on this one ^^I'll try it in few hours. Thanks again
CoBaLt2760
Hum, I've tried it, and I'm not sure to do it properly... By doing that, I juste manage to 1/ have an error If y try to pass GET parameters in file_get_contents('myfile.php?id=xxx'); 2/ without the param and just calling myfile.php, I have a blank page, with in the source, all my php code, not interpreted.. What I have done wrong?
CoBaLt2760
Ok, I've solved my problem.. In fact, I used the same technique as in this thread http://stackoverflow.com/questions/3954558/how-to-create-in-php-a-search-json-twitter-like
CoBaLt2760
A: 

I've solved my problem, in fact, I used the same way as in this thread:

How to make a search.php API

I return my 0 or 1 status in JSON and make a correct JSON ajax call.

CoBaLt2760