2

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); } }); 
15
  • I tried it locally, but I got just “abc” returned. Do you have an example page? Did you look in e.g. Firebug's Net panel, to see if the file gets actually send (with correct headers)? Commented Jun 10, 2010 at 14:15
  • What browser? I tried with Chrome and it didn't work. I need something that will work cross-browser. I'll get back to you with an example page. Commented Jun 10, 2010 at 14:16
  • Silly question, but one worth asking - you definitely running this on a server i.e. via HTTP? Commented Jun 10, 2010 at 14:18
  • @Marcel, you can try this: frw.se/callme.html it actually worked in IE8 when I tied that now, but still the same in chrome. Commented Jun 10, 2010 at 14:18
  • Firefox 3.6.3, but just tried it in Chromium 5.0.375.70 (using a local web server) and still no problem, both running under Linux. Commented Jun 10, 2010 at 14:20

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@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.
0

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> 

6 Comments

And it is fired, because an alert popped up.
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, what do you mean? Why does the files need to be on the same server?
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?
|
0

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.