$.ajax() success wont run function

2024/2/27 9:20:04

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.


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.


Related Q&A

Laravel 5.5 Axios POST results in 419 error

I am trying to make a POST-request to my Laravel API from Vue. The X-CSRF-TOKEN header is set correctly (I see this in the POST-package sent to the server).The route has the default web-middleware.Requ…

How to share state among components in Astro?

I believe Im taking the wrong approach in my code, how can I set a client side preference in a button click that is used as a prop in all my astro components globally? Or how should I do this? I know…

Initialize JQuery Datepicker with a blank value

This code still sets the field to todays date<script type="text/javascript">$(document).ready(function () {$(.date).datepicker({ dateFormat: "mm/dd/yy", changeMonth: true,chan…

AJAX POST to PHP without JQuery

I had a PHP assignment that I decided that I wanted to try and add AJAX to because in our class we will not learn AJAX just PHP. I cant seem to get the response to work. However in the network section …

checkbox on change ajax call

I have one checkbox. I want when I checked the checkbox so I get the 1 and then update a mysql query through that get value. I also want if I unchecked the checkbox so I get a value 0 so then I again u…

How to retrieve the Metadata from nodejs aws s3 getObject callback data?

I am trying to upload/download an audio chunk file to/from S3 using AWS node SDK. I have tried base64 approach and it works fine. But I am not able to get the Metadata back which I have bundled as part…

Firebase Firestore works with real database but not emulator

Im using Firebase and have started trying to run a local development instance using the Firebase Emulators. Im running v8.4.1 of Firebase Tools. When Im running with the real Firestore database everyth…

Uncaught TypeError: Object [object Object] has no method apply

I am receiving this Uncaught TypeError on a new website I am creating, but I cant work out what is causing the error.I have recreated the issue at the link below, if you take a look at your browsers JS…

ember-data - store.find(model) always queries the server

Details: ember-data-1.0.0.beta.3 and the default RESTAdapterI might have misunderstood how the store.find() method works, but, from my understanding, the following code should not query the server if t…

Allow alphanumeric with spanish regex in javascript?

Hi I tried the following code in javascript,if(/[^0-9a-z]/i.test(string)) {alert("oK WITH THE INPUT"); } else {alert("error"); }But I am getting a result OK , even I entered the @ c…