I'm trying to update an entry on the front end with a click and without a form. I'm a bit new with AJAX but would love to simply put a new title for the entry that the button relates to. I'm currently getting 500 Internal Server Errors
when trying.
{% for entry in currentUserSubmissions %}
{{ entry.title }}
{{ entry.submissionUrl }}
<a class="btn btn-approve btn-primary" data-id="{{ entry.id }}">Approve</a>
{% endfor %}
This is my AJAX
{% js at endBody %}
$('.btn-approve').on('click', function() {
var entryId = $(this).data('id');
var data = {
value: entryId,
name: 'entryId',
title: 'hello test'
};
var tokenName = '{{ craft.app.config.general.csrfTokenName }}';
data[tokenName] = '{{ craft.app.request.csrfToken }}';
// send ajax request
$.ajax({
method: "POST",
dataType: "json",
url: "/actions/entries/saveEntry",
data: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
success: function (data) {
console.log('success', data);
},
error: function (error) {
console.log('error', data);
}
});
});
{% endjs %}
/actions/entries/saveEntry 500 (Internal Server Error)
storage/logs/web.log