Codementor Events

Drupal - Update node field using Ajax jQuery

Published Jul 03, 2019

To update node field programmatically, first need to create a custom module as following:

Step 1:
You need to create a folder with your desired module name on sites/all/modules/ directory. And inside your newly created folder create two files as below:
your_custom.info
your_custom.module.

In your_custom.info file, add the following:
name = your_custom
description = describe the purpose of your module
core = 7.x

Note: Don't use uppercase letter for name, description and core, then you wont able to see that in your modules page.

Now go to yoursite.com/admin/modules page where you can see your custom module available to install. Please install and then use it as your desire.

Next, in your_custom.module file, add the following:
<?php
//your custom code goes here

Note: Don't close the php tag with ?> as per drupal standards.

Now we successfully created the custom module.

Step 2:
Create a custom javascript file here we assume as custom.js.
Inside this file, add the following:

$(document).ready(function(){
$.ajaxSetup({cache:false});
$.ajax(
{
url: path/to/your_custom.module
data: data
type: json
success: function(data){
console.log(data);
}
}
);
});

That's all now we have done all things to update a node field.

Discover and read more posts from Vengatesh
get started
post commentsBe the first to share your opinion
Show more replies