Reputation: 8411
$('a').click(function(event){
$('body').html('loading...');
$.post('www.sitename.com/hello',{site:"http//:www.google.com"},function(data) {
alert(data);
});
event.preventDefault();
});
I am using the above script to override the default behavior of the links .The site referred here returns the HTML of the 'site' parameter.but the page just stops after printing loading...
Upvotes: 1
Views: 149
Reputation: 236022
looks fine. Do you try to access a foreign domain?
Ajax Cross domain policy would not allow that.
Upvotes: 3
Reputation: 138017
Use jQuery.ajax to debug your code, by adding an error handler (the error could be on your hello
handler, a JavaScript access denied exception, etc):
$.ajax({
type: "POST",
url: "/hello",
dataType:"html",
data:{site:"http//:www.google.com"},
success:function(data){
alert(data);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
}
});
Also, make sure the url is http://, not http//: , and check the error console for other JavaScript errors - Ctrl+Shift+J on Firefox.
Upvotes: 1
Reputation: 13018
Try replacing your $.post() with:
$('body').load('www.google.com');
EDIT: this won't work because the whole dom of Google's page (including the header) will be inserted into the .
Upvotes: 0