views:

34

answers:

4

The alert box will display nothing, and not return any data from any URL when it should be showing the google page! Any ideas? I'm using POST because I'm trying to get it to send querystring data as well.

    $.ajax({
        type: "POST",
        url: "http://www.google.com",
        success: function(msg) {
            alert("Data Saved: " + msg);
        }
    });
A: 

I would try setting the dataType to html and see if that helps.

spinon
That doesn't even make sense
Tom Gullen
Wow!! So much hate out there. Can you please retract the down votes. Check the documentation for the ajax call. http://api.jquery.com/jQuery.ajax/Here is the brief info from the jquery documentation:dataTypeDefault: Intelligent Guess (xml, json, script, or html)The type of data that you're expecting back from the server. Not sure why that doesn't make sense? Please explain?
spinon
Just because I commented doesn't mean I necesserially down voted you, also no one is hating you. Every comment is appreciated. The reason I wrote it doesn't make sense is because I am attempting to retrieve the google homepage, which will return HTML anyway. With ajax requests I have never seen it necessary or possible (but I might be wrong) to specify the return type, I always treat returned data as text.
Tom Gullen
I wasn't necessarily saying that you down voted me. I just hating because it was two down votes right away when that is a valid possibility. But I just meant in general whoever down voted. Most people don't use because it does make an intelligent guess as to the contents. But sometimes it can be wrong in which case it is good to force the dataType so there is no confusion.I did misunderstand your post in that I just assumed that the google request was an arbitrary entry as to hide your internal page request. The cross domain comments have already been made so no need to mention again.
spinon
+2  A: 

yea TOm,

You are doing cross-domain scripting.

change the URL to a file which is in your own Domain.

$.ajax({
        type: "POST",
        url: "anyfileinYourDomain.xxx",
        success: function(msg) {
            alert("Data Saved: " + msg);
        }
    });
Muneer
I dont think, changing the domain makes any difference, as URL is suppose to link to a file.
Starx
Actually he is doing cross-domain access. There are different technique to do cross-domain Ajax.
Muneer
@Starx - not really... you're still bound with http://en.wikipedia.org/wiki/Same_origin_policy
Reigel
A: 

Try POST method

$.post(
      "http://www.gooogle.com", 
      { myvalue: 'hello' },
      function(data) {
         alert(data);
      });
Starx
A: 

You can do this only if you own google.com which I believe is at least unlikely:) (cross domain issues)

To overcome this you can make post to your server and let server connect to google.com, then you can respond to the user with data retrieved from google.com.

Lukasz Dziedzia