PHPRad Classic Initial 2.7.3 Forum

PHPRad Forum => Questions => Topic started by: pivar on November 06, 2021, 07:57:05 PM

Title: Trigger Update single field in Controller.php
Post by: pivar on November 06, 2021, 07:57:05 PM
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.
Title: Re: Trigger Update single field in Controller.php
Post by: willvin on November 08, 2021, 11:38:29 AM
@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.
Title: Re: Trigger Update single field in Controller.php
Post by: pivar on November 09, 2021, 07:08:26 PM
Many thanks!

csrfToken added and it works.