Skip to main content
Topic: Trigger Update single field in Controller.php (Read 452 times) previous topic - next topic

Trigger Update single field in Controller.php

I'm trying to create ajax call to update single field in database. My code is:

Code: [Select]
	$.ajax({
  type: "POST",
  url: 'http://localhost/test_project/dnkuh_stavke/editfield/1',
  data: ({ name: 'dnkuh_stavke_order', value: '13', pk:'1' }),
  success: function() {
             alert('Success');
        },
        error: function() {
            alert('Error occured');
        }
});


Link and fieldname should be fine I guess (copied from source code), value is hardcoded for test purposes.
I can't get this work so please help with correct code.

Re: Trigger Update single field in Controller.php

Reply #1
@pivar‍ you cant post data for updates or insertion if the link you are posting it to does not have the CSRF token passed to it. The URL line in your code should look like this.
Code: [Select]
url: 'http://localhost/test_project/dnkuh_stavke/editfield/1?csrf_token=' + csrfToken,

I suspect this might be your issue since you did not provide a clear error response gotten from the request. If the above does not fix your issue please provide the server response you get.

Re: Trigger Update single field in Controller.php

Reply #2
Many thanks!

csrfToken added and it works.