For security reasons, we cannot make cross-domain AJAX requests with jQuery. For example, I can’t call the load() method, and pass in ‘google.com’. 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
[php]
[/php]
The script above will get the “url” and add it with google.com. The result will be shown using echo.
Now, back to jquery
[javascript]
var dataa = $(“#url”).val();
$.ajax({
url: ‘api.php’,
data: dataa,
success: function(data) {
$(‘#short’).html(“<a target=_blank href=” + data + “>” + data + “</a>”);
}
[/javascript]
You’ll see the output now !