意外的令牌<在位置1的JSON中

时间:2018-04-19 06:58:20

标签: wordpress ajaxform

我在wordpress中遇到ajax提交表单的问题,这是我的代码:

AJAX

jQuery.ajax({
        url: $(this).attr('action'),
        type: "POST",
        dataType: "JSON",
        data: formData,
      })
      .success(function( response ) {
        if( response.success ) {
          console.log(response);
        } else {
          console.log('Error: ' + response.data);
        }
      })
      .error(function( xhr, ajaxOptions, thrownError ) {
        console.log('Request failed: ' + thrownError.message);
      });

PHP (functions.php):

add_action ('wp_ajax_call_store_voting', 'store_voting') ;
add_action ('wp_ajax_nopriv_store_voting', 'store_voting') ;

function store_voting () {

    $return_value = 'Successful!';

    echo json_encode($return_value);
    exit();
}

0 个答案:

没有答案