1

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)

1
  • What does your logs say? storage/logs/web.log
    – Jørgen
    Commented May 13, 2019 at 12:13

1 Answer 1

1

Try changing the url from "/actions/entries/saveEntry" to "/actions/entries/save-entry"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.