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

  • Home
  • SEARCH
  • 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 7487831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:40:02+00:00 2026-05-29T14:40:02+00:00

In a JS file I have this: $.ajaxSetup({ type: ‘POST’, contentType: application/json; charset=utf-8, dataType:

  • 0

In a JS file I have this:

$.ajaxSetup({
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: {},
    error: function (jqXHR, textStatus, errorThrown) {
        debugger;
    }
});

Then further on in the file I instantiate an object that has an AJAX call in it’s constructor to fill out some values.

function RequestViewModel() {
    var self = this;
    (...)
    // Initalization Methods
    $.ajax({
        url:ajaxAddress + 'LoadStates',
        success: function (data) {
            debugger;
        }
    });
}
var model = new RequestViewModel();

However, when the ajax call is made in the code, ‘xml’ is being used as the dataType instead of JSON. This is causing my web service call to break and I always get sent to the error callback of the AJAX call. If I move the settings inside the actual AjAX call, the call works and data is returned from the server. For some reason, the global setting isn’t being honored.

My question is why isn’t this working? I’ve used this same technique several other times without this problem.

I’m using jQuery version 1.7.1.

UPDATE

It seems like the problem is on line 7517 of the jQuery file. It is doing an IF statement that is being evaulated to false and is skipping over setting the correct Content Type in the request header.

  • 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-05-29T14:40:03+00:00Added an answer on May 29, 2026 at 2:40 pm
    • Try putting your .ajaxSetup inside a document ready wrapper.(NOT likely the cause though)
    • Try using jQuery.ajaxSetup instead of $.ajaxSetup
    • It is recommended that global event handlers not be in the ajaxSetup. move error: to $.ajaxError( instead:

      jQuery.ajaxError( function (e, jqxhr, settings, exception) {
      alert(settings.url + " Failed");
      });

    Example if you have a div with a log class (puts some text in if any error occurs:

    $("div.log").ajaxError(function() {
      $(this).text( "Triggered ajaxError handler." );
    });
    

    NOTE: when you refactor, make sure to remove the LAST comma.

    Also, if you are using the latest version of jQuery (1.7.1 at the moment) you can simplify:

    contentType: "application/json; charset=utf-8",
    

    to

    contentType: "application/json",
    

    EDIT: quick, dirty global handler:

    $(document).ajaxError(function(e, xhr, settings, exception) {
        alert('error in: ' + settings.url + ' \\n'+'error:\\n' + exception);
    }); 
    

    EDIT2: SOME resources also put an empty data set sent as: (with quotes)

    data: "{}",
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
In my button.xul file I have this: <script type=application/x-javascript src=chrome://mf_unblocker/content/button.js/> <toolbarbutton id=custom-button-1 label=Custom tooltiptext=MAFIAAFire:
In an xsd file I have this element base type : <xs:complexType name=event abstract=true
This is a GUI java application, I have a run.sh file and I want
I have this code in my HTML form: <form action=cart.php method=post> <input type=hidden value=1
I have this file file.txt which I want to split into many smaller ones.
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
I have .lib file with its header (.h) file. This file have a few
I use an externel javascript file and i have this, function getdropdownvalue() { alert($(#<%=DLState.ClientID%>));
I have this exported file of some weird (standard for this industry!) format, which

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.