I am trying to put comments on Facebook wall using jquery.
But my ajax call not alowing external url .
can anyone explain how can we use external url with jquery ?
below is my code :
var fbUrl="https://graph.facebook.com/16453004404_481759124404/comments?access_token=my_token";
$.ajax({
url: fbURL ,
data: "message="+commentdata,
type: 'POST',
success: function (resp) {
alert(resp);
},
error: function(e){
alert('Error: '+e);
}
});
its giving xmlhtttprequest error.
All of these answers are wrong!
Like I said in my comment, the reason you're getting that error because the URL fails the "Same origin policy", but you can still us the AJAX function to hit another domain, see Nick Cravers answer on this similar question:
With this in mind, the follow code should work:
Hi url should be calling a function which in return will give response
try using/calling API facebook method
JQuery and PHP
In PHP file "contenido.php":
In html:
google the javascript same origin policy
in a nutshell, the url you are trying to use must have the same root and protocol. so http://yoursite.com cannot access https://yoursite.com or http://anothersite.com
is you absolutely MUST bypass this protection (which is at the browser level, as galimy pointed out), consider the ProxyPass module for your favorite web server.
it is Cross-site scripting problem. Common modern browsers doesn't allow to send request to another url.
I think the only way is by using internel PHP code like MANOJ and Fernando suggest.
curl post/get in php file on your server --> call this php file with ajax
The PHP file let say (fb.php):
Than use AJAX GET to
from your server.
Or do this with simple HTML and JavaScript from externel server: