Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:37:18+00:00 2026-06-17T14:37:18+00:00

Here’s my jQuery script: $.ajax({ type: ‘POST’, url: ‘zipCodes.php’, data: searchZipCode, cache: false, success:

  • 0

Here’s my jQuery script:

$.ajax({
type: 'POST',
url: 'zipCodes.php',
data: searchZipCode,
cache: false,
success: function(response) {
    alert ('response from db search: ' + response);
},
error: function(response) {
    console.log(response);
    alert('Query failed, php script returned this response: ' + response);
}
});

The above script is in the head tag of the html file the form is in. The php script is in the same folder as the html file.

Here’s the form:

<form id="frmZipCodeSearch" action="">
    <label for="txtZipCodeSearch">Enter a zip code</label>
    <input type="text" id="txtZipCodeSearch" length="10" maxlength="5" />
    <input type="submit" id="btnSubmitZipCodeSearch" />
</form>

I also have verified that “searchZipCode” has a value.

Every time I run the search I get the alert from the error part of the ajax call, which says

Query failed, php script returned this response: [object Object]

and this shows in the console:

Object {readyState: 0, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}

I’ve tried stripping the php script down to just an echo. I’m not getting any php error logs generated in the folder with the script on the server. Nothing I change seems to give me a different result. With one exception:

The only time I got a different result was when I stripped out the ajax and moved the php script to the file with the form and did a “regular” html form POST method. That worked. But I don’t think the path is wrong when the php is a different file because I’m not getting a “file not found” in the console.

What the heck am I missing here?

[Additional Info]
In response to hek2mgl’s answer, I added xhr to the error response and did get some more info in the console:

Uncaught ReferenceError: xhr is not defined     zipCodeSearch.html:57
    $.ajax.error                                zipCodeSearch.html:57
    l                                           jquery-1.8.3.min.js:2
    c.fireWith                                  jquery-1.8.3.min.js:2
    T                                           jquery-1.8.3.min.js:2
    r                                           jquery-1.8.3.min.js:2

All other jQuery I’m using is working fine, but this is the first time I’ve used v1.8.3 myself.

[Answer – credit hek2mgl]
As hek2mgl explained in our crazy-long discussion, I was submitting the form twice, because the ajax call was within the click event of the form’s button.

The fix for this was to move the ajax call out of the click event into its own function, and after my client-side validation, call the ajax function and add “return false;” after the function call.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:37:19+00:00Added an answer on June 17, 2026 at 2:37 pm

    The $.ajax error callback is defined as follows:

    Type: Function( jqXHR jqXHR, String textStatus, String errorThrown )

    You’ve dumped the whole jqXHR object. Unlike the success function, the respone text itself is not a param of the error callback. To retrieve the response text (if any) use this:

    error: function(xhr) {
        var response = xhr.responseText;
        console.log(response);
        var statusMessage = xhr.status + ' ' + xhr.statusText;
        var message  = 'Query failed, php script returned this status: ';
        var message = message + statusMessage + ' response: ' + response;
        alert(message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is what I am currently doing. PHP echo's out the recent post in
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is the two scripts I have Script 1: <? include('config.php'); $json = $_POST['payload'];
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Here is my code for the POST request to the server. The JSON to
Here's the code require_once 'functions.php'; require_once 'cfg.php'; $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $db);
Here is my code: <?php $variable1 = 00001; $variable2 = (sprintf('%04d', $variable1 + 1));

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.