C. Hediger C. Hediger - 1 year ago 91
Javascript Question

jquery get() does not return any response

I actually try to load a php script and get some return values.

I tried the following code:

It does the GET request correctly as i can see with firebug.
But it never shows me any response with the alert box.

I have also tried the following code:

type: "GET",
url: "test.php",
dataType: "html"
}).done(function (res) {
// Your `success` code
}).fail(function (jqXHR, textStatus, errorThrown) {
alert("AJAX call failed: " + textStatus + ", " + errorThrown + " - " +jqXHR.status);

This returns ERROR undefined code 0

I hope someone see the mistake.


This is my original code:

$.get( "test.php", function( data ) {
alert( "Data Loaded: " + data );

This also does not work!

This is my test.php:


echo "Hellllooouuu";


Answer Source

Try to use done callback, see this:


About jqXHR Object:

"As of jQuery 1.5, all of jQuery's Ajax methods return a superset of the XMLHTTPRequest object. This jQuery XHR object, or "jqXHR," returned by $.get() implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see Deferred object for more information). The jqXHR.done() (for success), jqXHR.fail() (for error), and jqXHR.always() (for completion, whether success or error; added in jQuery 1.6) methods take a function argument that is called when the request terminates.

The Promise interface also allows jQuery's Ajax methods, including $.get(), to chain multiple .done(), .fail(), and .always() callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately."


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download