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 6241859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:50:38+00:00 2026-05-24T11:50:38+00:00

In a ajax-driven site I have added some default data using the ajaxSetup, ala

  • 0

In a ajax-driven site I have added some default data using the ajaxSetup, ala this:

var revision = '159';
$.ajaxSetup({
    dataType: "text json",
    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
    data: {
        r: revision
    }
});

This is to ensure cache-miss when a new revision is deployed and the frontend ask for html templates or json-data from the backend. The backend and frontend share the same revision number for this reason.

The problem is that the backend it somewhat unhappy about getting the parameter ‘r’ when the frontend does a PUT, POST or DELETE. Is there no way to tell jQuery’s ajax that this data should only be used when doing GET requests and not when doing POST, PUT or DELETE requests.

UPDATE:

I tried the beforeSend function first, since I knew it. However changing settings.data was possible, but any change seemed to vanish when beforeSend returned. It may have been my fault… 🙂

I have settled on the ajaxPreFilter instead. It was not easy as pie though. The options.data is not an object, but the result of $.param(object), so the first challenge was to un-parameterize it. I ended up with this:

var revision = '159';
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
    // do not send data for POST/PUT/DELETE
    if (originalOptions.type !== 'GET' || options.type !== 'GET') {
        return;
    }

    var data = originalOptions.data;
    if (originalOptions.data !== undefined) {
        if (Object.prototype.toString.call(originalOptions.data) === '[object String]') {
            data = $.deparam(originalOptions.data); // see http://benalman.com/code/projects/jquery-bbq/examples/deparam/
        }
    } else {
        data = {};
    }

    options.data = $.param($.extend(data, { r: revision }));
});
  • 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-24T11:50:39+00:00Added an answer on May 24, 2026 at 11:50 am

    Starting jQuery 1.5, you can handle this much more elegantly via Prefilters:

    var revision = '159';
    $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
        // do not send data for POST/PUT/DELETE
        if(originalOptions.type !== 'GET' || options.type !== 'GET') {
            return;
        }
    
        options.data = $.extend(originalOptions.data, { r: revision });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery to drive my AJAX UI. I have a table of data,
I have a primarily Ajax-driven site, the content of which is populated by making
I'm using the jquery address plugin to build an ajax driven site, and i've
If I have a rich AJAX-driven GUI in ASP.NET MVC, how would I unit
Does it open any attack vector if an ajax-driven site uses a unique token
I've created an ajax driven flot line chart that I would like to have
I have an admin that is almost completely ajax driven. When the page loads
I have a very simple jQuery/ajax script for a membership driven website. The script
.ajax({ type: 'POST', url: '..serverices/ajaxserver.asmx', data: 'lname='+ $('#lastname').val() }); return false; if #lastname has
ajax tutorial on w3school at http://www.w3schools.com/ajax/ajax_database.asp In this function (function GetXmlHttpObject()), it creates a

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.