tags:

views:

46

answers:

3

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);
    }
});
A: 

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>
artlung
Still returns nothing.
Filip Ekberg
And it *is* fired, because an alert popped up.
Marcel Korpel
Filip, if the callme.html file you are calling is on a different server than the firing page, it will fail, because of the same-origin policy. Is that what's happening?
artlung
@artlung, what do you mean? Why does the files need to be on the same server?
Filip Ekberg
Same-origin policy for JavaScript: https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript
artlung
So how do you solve that? By setting the document.domain each time you want to create an ajax query? How does google analytics solve this when they need to query a page on a totaly different domain?
Filip Ekberg
I solve it by putting the content I want to make ajax calls for on the same server. This article includes a discussion about how Google Analytics doesn't violate same-origin: http://taossa.com/index.php/2007/02/08/same-origin-policy/
artlung
+1  A: 

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

This should be a comment.
Filip Ekberg
@Filip: Yes, but your rep has to be 50 to be able to comment on other's questions and answers. That said, (s)he could have simply upvoted my first comment, which said the same.
Marcel Korpel
A: 

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!

Filip Ekberg