Ajax & WordPress on Front End - Database not updating

前端 未结 4 1802
离开以前
离开以前 2021-01-14 17:59

So I\'m working on a WordPress website. I\'m having a bit of a difficult time getting the user input to update the database.

JS:

var ID = $(this).at         


        
4条回答
  •  感情败类
    2021-01-14 18:34

    Here is the issue, for ajax requests we use http://example.com/wp-admin/admin-ajax.php.
    Also your data string should cantain &action=editItems ( same as you use in wp_ajax_editItems )

    You ajax request code should look like...

      $.ajax({
        type: "POST",
        url: "/wp-admin/admin-ajax.php",
        data: dataString + '&action=editItems',
        cache: false,
        error: function(xhr, status, error) {
          var err = eval("(" + xhr.responseText + ")");
          alert(err.Message);
        },
        success: function (html) {
          $("#name_"+ID).html(name);
          $("#createDate_"+ID).html(createDate);
          $("#stats_"+ID).html(stats);
          $("#dateExpire_"+ID).html(dateExpire);
        }
      });
    

    For more details check out https://codex.wordpress.org/AJAX_in_Plugins

    Hope that helps :)

提交回复
热议问题