Drupal Ajax: Passing values ​​by url vs data parameter

What is the difference between using:

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

vs

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

In the first case, you must access the node variable as a parameter in the callback function, and in the second case, you will access it with $ _POST ['node']? Would the second method not always be better, but I see that many people do it the first way. Not to say that the second way is both. Still looking at form tokens, but first trying to figure out this basic bit.

Also wonders about case 1, assuming this ajax is launched with a button, how can you get a person to directly enter the URL, mysite / module / get / 20 and activate it? Just checking that $ _POST ['ajax'] == true does this? Or is there a security hole?

+3
source share
1 answer

:

, node node, . , , "get" ( ), - (, ).

, - "" , , "" GET POST, , , "" , URL-.

"" Drupal:

Drupal , Wildcard Loader Arguments ( ​​ Drupal 6). , URL- hook_menu :

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

yourModule_callback() , node obect nid, %node Drupal a node_load() . , node, POST.

, .

, Drupal , URL AJAX, javascript. , yourModule_callback(), , node, , . $ajax == TRUE POST. , , AJAX, JSON. , , , (, , , ...).

, URL- AJAX/AJAX.

+4

Source: https://habr.com/ru/post/1730161/


All Articles