Hey,
I'm trying to use the jQuery.Get() function to return the contents of a webpage.
Something along the lines of -
var data = $.get("http://mysite...../x.php");
I know the above is wrong, can someone help my out here?
Cheers,
Hey,
I'm trying to use the jQuery.Get() function to return the contents of a webpage.
Something along the lines of -
var data = $.get("http://mysite...../x.php");
I know the above is wrong, can someone help my out here?
Cheers,
try to use this:
$.get("test.php", function(data){
alert("Data Loaded: " + data);
});
Is http://mysite..... on the same domain as the jQuery $.get(..) ??
If not, you'll get a cross-domain error.
$.get does not return the result of the query. It is an AJAX call and the first A in AJAX stands for "asynchronous". That means that the function returns before the AJAX request is complete. You therefore need to supply a function as the second argument of the call:
var data = $.get("http://mysite...../x.php", function(data) {
alert(data);
});
See http://api.jquery.com/jQuery.get/ for more examples and options that you can set.
jQuery ajax calls are asynchronous, so you'll need to do something on the callback of the get.
$.get('http://mysite...../x.php', function(data) { $('.result').html(data); alert('Load was performed.'); });
Also, bear in mind that $.get is just a convenience handler. Even the documentation (http://api.jquery.com/jQuery.get/) indicates that it calls $.ajax. With that in mind, it's always a better idea to call the method directly, as it's a couple less calls pushed on to the stack and you save a few CPU cycles.