Jquery Ajax Post在Wordpress中不起作用

Jquery Ajax Post在Wordpress中不起作用,jquery,html,ajax,wordpress,Jquery,Html,Ajax,Wordpress,我有一个简单的ajax post方法将数据发送到Web api,但即使控制台中没有错误,该代码也不会发布数据。 请帮我解决这个问题,我也用所描述的jQuery更改了$。我正在使用Wordpress 4.9。 以下是用wordpress编写的源代码 代码 var ServiceAndVisitroData = { //orderid selectedService: selecteddata, userId: $('#userid').val().trim(), OrderId:

我有一个简单的ajax post方法将数据发送到Web api,但即使控制台中没有错误,该代码也不会发布数据。 请帮我解决这个问题,我也用所描述的jQuery更改了$。我正在使用Wordpress 4.9。 以下是用wordpress编写的源代码

代码

var ServiceAndVisitroData = {
  //orderid
  selectedService: selecteddata,
  userId: $('#userid').val().trim(),
  OrderId: $('#orderid').val().trim(),
  DealInfo: $('#deals').val().trim(),
  IPAddress: userip,
  deviceName: userDevicedata[0],
  OSName: jscd.os + "," + jscd.osVersion,
  browserName: jscd.browser + "," + jscd.browserMajorVersion + "," + jscd.browserVersion,
  IsCustomllogo: false,
  userToken: cookiesplit[1],
  firstname: cookiesplit[2],
  lastname: last[0]

};

$.ajax({
  type: "POST",
  url: 'http://test.com/api/agency/postcheckout',
  // contentType: "application/json; charset=utf-8",
  //data: JSON.stringify(ServiceAndVisitroData),
  data: ServiceAndVisitroData,
  dataType: "json",
  success: function (result) {
    //  alert(result.firstname);
    //  alert(result.lastname);
    //  alert(result.tokenn);
    // alert(result.useridd);

    if (result.success == "pymt") {

      window.location.href = 'http://test.com/api/agency/payment/' + result.Id + '/' + result.Showbutton + '/' + result.firstname + '/' + result.firstname + '/' + result.lastname
      return false;

    }
    else if (result.success == "ord") {




      window.location.href = 'http://test.com/api/agency/order/' + result.Id + '/' + result.Showbutton + '/' + result.firstname + '/' + result.lastname;
      return false;
    }
    else {
      // alert('Your form has been submitted.');

      //alert(result.id);
      window.location.href = '/';
    }
  },
  error: function (result) {
    alert('Oh no ');
    window.location.href = result.Url;
  }

});

你必须这样做

 var ServiceAndVisitroData = {
                        //orderid
                        selectedService: selecteddata,
                        userId: $('#userid').val().trim(),
                        OrderId: $('#orderid').val().trim(),
                        DealInfo: $('#deals').val().trim(),
                        IPAddress: userip,
                        deviceName: userDevicedata[0],
                        OSName: jscd.os + "," + jscd.osVersion,
                        browserName: jscd.browser + "," + jscd.browserMajorVersion + "," + jscd.browserVersion,
                        IsCustomllogo: false,
                        userToken: cookiesplit[1],
                        firstname: cookiesplit[2],
                        lastname: last[0]

                    };

        jQuery.ajax({
          url: "<?php echo admin_url( 'admin-ajax.php' );?>", 
          data: {action: 'ajax_call_back_func', data:ServiceAndVisitroData},
          type: "POST",
          success: function(result, textStatus, XMLHttpRequest){

                            if (result.success == "pymt") {

                                window.location.href = 'http://test.com/api/agency/payment/' + result.Id + '/' + result.Showbutton + '/' + result.firstname + '/' + result.firstname + '/' + result.lastname
                                return false;

                            }
                            else if (result.success == "ord") {
                                window.location.href = 'http://test.com/api/agency/order/' + result.Id + '/' + result.Showbutton + '/' + result.firstname + '/' + result.lastname;
                                return false;
                            }
                            else {
                                // alert('Your form has been submitted.');

                                //alert(result.id);
                                window.location.href = '/';
                            }
                        },
                        error: function (result) {
                            alert('Oh no ');
                            window.location.href = result.Url;
                        }

                    });

首先遵循这个简单的教程:,然后根据您的要求自定义它。我应该在哪里写帖子Url?我得到了这个未捕获的类型错误:无法读取未定义的属性“propHooks”?为什么使用“”作为Url?这是wordpress默认的ajax Url
function ajax_call_back_func(){
  print_r($_POST);exit;
}

add_action('wp_ajax_ajax_call_back_func',  'ajax_call_back_func');
add_action('wp_ajax_nopriv_ajax_call_back_func', 'ajax_call_back_func');