用jquery把当前html的参数从url中解析orderId和username POST到apiContinue如果http状态码200则把返回的html写到div 123中否则写到div 456中
以下是可能的代码实现:
$(document).ready(function() {
// 从url中解析orderId和username
const urlParams = new URLSearchParams(window.location.search);
const orderId = urlParams.get('orderId');
const username = urlParams.get('username');
// 发送POST请求到/api/Continue,并传递orderId和username参数
$.post('/api/Continue', { orderId, username }, function(data, status) {
// 根据http状态码判断是否成功
if (status === 'success') {
// 请求成功,将返回的html写到div 123中
$('#123').html(data);
} else {
// 请求失败,将返回的html写到div 456中
$('#456').html(data);
}
});
});
需要注意的是,上述代码中的/api/Continue路径和#123、#456选择器需要根据实际情况进行修改。此外,由于POST请求是异步的,因此需要在回调函数中处理返回的数据
原文地址: https://www.cveoy.top/t/topic/eBmm 著作权归作者所有。请勿转载和采集!