Answers.Body: <p>Try changing the url from "/actions/entries/saveEntry" to "/actions/entries/save-entry"</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-13T13:46:09.313Z
Answers.LastActivityDate: 2019-05-13T13:46:09.313Z
Answers.UserDisplayName: Arjan
Body: <p>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 <code>500 Internal Server Errors</code> when trying.</p>
  
  <pre><code>{% for entry in currentUserSubmissions %}
    {{ entry.title }}
    {{ entry.submissionUrl }}
    &lt;a class="btn btn-approve btn-primary" data-id="{{ entry.id }}"&gt;Approve&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>This is my AJAX</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
  <blockquote>
    <p>/actions/entries/saveEntry 500 (Internal Server Error)</p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-05-13T12:13:03.943Z
Comments.Text: What does your logs say? `storage/logs/web.log`
Comments.UserDisplayName: Jørgen
Tags: <templating><ajax>
Title: AJAX Update Entry (500 Internal Server Error)
ThreadText: # AJAX Update Entry (500 Internal Server Error)
  
  (Asked by: username_0 on 2019-05-13)
  
  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)
  
  **Tags:** templating, ajax
  
  > **Comments:**
  > **username_1**: What does your logs say? `storage/logs/web.log`  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-05-13. Score: 1
  
  Try changing the url from "/actions/entries/saveEntry" to "/actions/entries/save-entry"
  
  
  ---
  
  