Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  150] [ 2]  / answers: 1 / hits: 28349  / 11 Years ago, wed, september 18, 2013, 12:00:00

My question regards the $.ajax() jQuery method. I can't get the success parameter in $.ajax() to work.



This works:



$.ajax({
type: 'POST',
url: /getCodes.php?codes=billingCodes&parent=+$('#wClient').val(),
dataType: 'json',
success: window.alert(inside aJax statement)

});


This does not:



 $.ajax({
type: 'POST',
url: /getCodes.php?codes=billingCodes&parent=+$('#wClient').val(),
dataType: 'json',
success: function(){
window.alert(inside aJax statement);
}
});


In the first case, I get a JavaScript alert window that lets me know the $.ajax() I called is working. All that is changed in the second block of code is I put the window.alert() inside a function() { window.alert(); }.



The point of this is to verify that the $.ajax is running so I can put some actual useful code in the function(){} when the $.ajax runs successfully.


More From » ajax

 Answers
58

In your second example nothing will happen unless you get a successful call back from the server. Add an error callback as many here have suggested to see that indeed the ajax request is working but the server is not currently sending a valid response.


$.ajax({
type: "POST",
url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
dataType:"json",
success: function(response){
alert(response);
},
error: function(jqXHR, textStatus, errorThrown){
alert('error');
}
});

helpful Link in tracking down errors.


[#75608] Tuesday, September 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anabellejaynav

Total Points: 176
Total Questions: 105
Total Answers: 105

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;