Cross domain ajax quering with JQuery

For security reasons, we cannot make cross-domain AJAX requests with jQuery. For example, I can’t call the load() method, and pass in ‘’. You may get error message “Access denied” if you try so.

Fortunately, I found a solution for this by searching on google.

Jquery can only post queries within the same domain. So we have to set a proxy between us and the world for this purpose.

Therefore I created a simple php file called api.php



The script above will get the “url” and add it with The result will be shown using echo.

Now, back to jquery

var dataa = $(“#url”).val();
url: ‘api.php’,
data: dataa,
success: function(data) {
$(‘#short’).html(“<a target=_blank href=” + data + “>” + data + “</a>”);

You’ll see the output now !

Leave a Reply

Your email address will not be published.