我在 Woocommerce 平台上使用 Wordpress。成功下订单后,我必须将选定的订单详细信息发送到 API(第 3 方会计系统)。
当前的 jquery ajax 代码
j.ajax({
type: 'POST',
url: 'https://mywebsite/api/orderupload',
cache: false,
data: {
},
beforeSend:function() {
},
success: function (result) {
},
error: function(xhr,status,error) {
console.log(error);
},
complete:function(){
}
});
上面 post 请求必须在data {}里面的 json 数据的结构是:
{
"order": {
"customer": {
"type": "public",
"vat": "false",
"org_nr": "123456-789",
"name": "Carl Lorem",
"phone": "639055543227",
"address": {
"name": "Carl Lorem",
"address": "Riften Street",
"zipcode": "2323",
"city": "Dawnstar City",
"country": "US"
},
"email": "[email protected]"
},
"transaction": {
"storage": {
"name": "Los Angeles",
"location": "Road Earth",
},
"insurance": {
"name": "Igsum Nat",
"cost": "30"
},
"date": {
"start": "2018-4-23",
"end": ""
}
}
}
}
你知道如何为我的帖子请求构建我的 json 数据吗?任何想法表示赞赏。谢谢
{
"order": {
"customer": {
"type": "public",
"vat": "false",
"org_nr": "123456-789",
"name": "Carl Lorem",
"phone": "639055543227",
"address": {
"name": "Carl Lorem",
"address": "Riften Street",
"zipcode": "2323",
"city": "Dawnstar City",
"country": "US"
},
"email": "[email protected]"
},
"transaction": {
"storage": {
"name": "Los Angeles",
"location": "Los Angeles, Road Street"
},
"insurance": {
"name": "Igsum Nat",
"cost": "30"
},
"date": {
"start": "2018-4-23",
"end": ""
}
}
}
}
您附加的 json 无效,我向您发送正确的 json,
关于ajax部分:
$.ajax({
type: "POST",
url: '/mywebsite/api/orderupload',
data: ("myjson": myjson},
dataType: 'json'
success: function (response) {
console.log(response)
}
error: function(xhr,status,error) {
console.log(error)
},
})
myjson 变量是您要通过 ajax 发送的 json。之后,您的后端将接管您的处理方式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句