Filip Ekberg
Filip Ekberg

Reputation: 36287

Using jQuery to perform a GET request and using the resulting data

I have a page, let's call it "callme.html" which only has this content:

abc

Now I want to fire the following:

$.get("callme.html", function (data) {

    alert(data);     

}, "text");

I am using jQuery 1.4.2 mini and the page is called but the alert is empty.

Any ideas why? I'd like the popup to contain abc

I've also tried the following

$.ajax({
   url: "callme.html",
   async: false,
   success: function (data) {
       alert(data);
    }
});

Upvotes: 2

Views: 115

Answers (3)

Filip Ekberg
Filip Ekberg

Reputation: 36287

I solved it with using jsonp instead and using pre-loaded images in javascript.

    $.getJSON("www.mypage.com?callback=?",
    function (data) {
        requestid = data.guid;
    });

When you provide callback=? it will be replaced by getJSON with the appropriet identifier for the callback function.

However, now I must have control over mypage.com, which I have. So problem solved!

Upvotes: 0

Incognito
Incognito

Reputation: 20765

Use chrome's developer tool, or fire bug. This lets you see any errors, or where the request went, if it was successful, etc...

Upvotes: 1

artlung
artlung

Reputation: 34013

Your $.get() call is fine. You need to wrap it so that it fires on load.

This works for me:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    $.get("callme.html", function (data) {
        alert(data);     
    }, "text");
});
</script>

Upvotes: 0

Related Questions