views:

72

answers:

3
$('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...

+3  A: 

looks fine. Do you try to access a foreign domain? Ajax Cross domain policy would not allow that.

Kind Regards --Andy

jAndy
yeah thats why i switched to IE
Bunny Rabbit
A: 

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 .

ZippyV
+1  A: 

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.

Kobi
yeah that was really helpful also ctr+shift+j was a huge addition to my knowledge .
Bunny Rabbit
i used html.body(data); but seems that would just inset the text of the page into the body and not the images etc.Is there a way data can be used to get the whole page (images+data+css and whatever the page may contain.)
Bunny Rabbit
Not really. The images and files fail because they have the wrong relative url... You can fix most of these using the `<base>` tag, but some will get away. You still have a problem with outgoing links, or dead relative links (again, `<base>` can help partially). Be careful, the work can get difficult - I know a program that rewrites your JS to avoid uncontrolled redirect! (it even changes `eval` statements)
Kobi