【发布时间】:2018-04-25 21:07:39
【问题描述】:
我有一个简单的 ajax 发布方法来将数据发送到 Web api,但是即使控制台中没有错误,这段代码也不会发布数据。 请帮我解决这个问题,我还用 jQuery 更改了 $,如描述 Here。我正在使用 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;
}
});
【问题讨论】:
-
首先按照这个简单的教程:wptricks24.com/how-to-use-ajax-wordpress,然后根据您的要求进行自定义
标签: jquery html ajax wordpress