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)

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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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