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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:49:13+00:00 2026-05-13T14:49:13+00:00

What is the difference between using: $.ajax({ type: ‘POST’, url: Drupal.settings.basePath + ‘module/get/’ +

  • 0

What is the difference between using:

 $.ajax({
  type: 'POST',
  url: Drupal.settings.basePath + 'module/get/' + node,
  dataType: 'json',
  data: { 'ajax' : true }
 });

versus:

 $.ajax({
  type: 'POST',
  url: Drupal.settings.basePath + 'module/get',
  dataType: 'json',
  data: { 'ajax' : true, 'node' : node }
 });

In the first case you’d access the node variable as a parameter in the callback function and in the second case you’d access it with $_POST[‘node’] right? Wouldn’t the second method always be better, but I see a lot of people doing it the first way. Not to say that the second way is that secure either. Still looking into form tokens, but trying to figure out this basic bit first.

Also wondering for case 1, assuming this ajax is triggered by a button, how do you stop a person from entering directly into the url, mysite/module/get/20 and activating it? Does simply checking that $_POST[‘ajax’] == true do that? Or is there still a security hole there?

  • 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-13T14:49:14+00:00Added an answer on May 13, 2026 at 2:49 pm

    No real difference at first sight:

    Assuming that your ‘node’ variable is just a node id, there is not much difference between the two. Semantically, both seem to perform a ‘get’ operation (even though they are technically post requests), as they just retrieve data without changing any state on the server (ok, that’s another assumption).

    Security wise, there is no relevant difference either – both can be ‘forged’ easily and the difference boils down to the same as with the ‘standard’ GET vs. POST debate, that is, no difference except that the first exposes the parameters a wee bit more ‘accessible’ to the casual observer, as they are in plain sight within the URL.

    But a ‘convenience’ difference within Drupal:

    Within Drupal, the first version is often encountered because it can make use of the Wildcard Loader Arguments functionality (introduced in Drupal 6). Let’s say your callback URL is defined in hook_menu like so:

    $items['module/get/%node'] = array(
    'title' => 'Foo',
    'type' => MENU_CALLBACK,
    'page callback' => 'yourModule_callback',
    'page arguments' => array(2),
    );
    

    With this, yourModule_callback() will be called with its first parameter already being the fully loaded node obect for the passed in nid, as %node tells Drupal to execute a node_load() on the parameter before handing it over to the callback function. Using the second version of your example, the callback function would have to load the node object itself, after extracting it from the POST data.

    So a convenience thing here.

    Additionally, a common pattern within Drupal is to use the same callback URL for an AJAX request as for its non javascript ‘fallback’ alternative. So when yourModule_callback() is invoked, it can do whatever it is intended to do with the passed in node first, basically assembling its result. After that is done, it only checks for $ajax == TRUE within the POST data. If it is there, it knows that the result is intended for an AJAX request, so it might output the result as a JSON. If it is not there, it knows that a full page cycle is going on, and can adjust its output accordingly (e.g. rebuilding a form, regenerating a whole page, whatever …).

    That way, you don’t have to register separate URLs for your non AJAX/AJAX callbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 298k
  • Answers 298k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You want just List<A> for mixed. My reasoning: you want… May 13, 2026 at 7:32 pm
  • Editorial Team
    Editorial Team added an answer Since SQL Server CE is considered to be an "application… May 13, 2026 at 7:32 pm
  • Editorial Team
    Editorial Team added an answer Analyzing stumbleupon.com: The "header" consists actually of two divs: wrapperHeader… May 13, 2026 at 7:32 pm

Related Questions

Can you you tell me what would be the difference between of the ID:
What is the difference between using an environment variable, like PATH, as $PATH or
I was just reading this: http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx And had some questions about some of the
I am using flash as3, php and mysql What is the difference between: $username
I've recently installed MbUnit version 2.4.2.355 on our build server which runs via Cruise

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.