获取 - 请求,以在Alert()中显示结果

I would like to create an app that will send out a get request, then take the response and display it on the page, this is part of my learning process, ultimately i would like to have the response be parsed and turned into elements etc. but for now i am having trouble accessing the information within the response. How can i alert() any of the results in the response?

the results of the script below ranged from undefined, to [object ojbect]

    <script type="text/javascript">
                    var bbz;
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "MyDomain - its defined and on the web",
success: function(response) {

bbz = response;

alert(bbz.length);
alert(bbz);
alert(bbz[0]);
 }
});


        </script>

It looks to me like you are expecting a JSON response...

I am assuming this because of the way you are accessing properties of the response object -

bbz = response;
alert(bbz.length);

You'll want to set your dataType to "json".

If you set the dataType property to html, you should be able to simply return HTML.

You set dataType: "jsonp" which attempts to parse a jsonp object out of the data that is to be returned. However, what you really want is the markup that is in the file you are requesting data from. In order to do this, you must state the correct return type, so that the AJAX knows what data to give you, i.e. you tell the AJAX how to parse the data.