当表单提交成功或失败后,您的API可以返回适当的响应给WordPress或jQuery。以下是一个解决方案示例:
// 在PHP中的示例代码
$response = array(
'status' => 'success',
'message' => 'Form submitted successfully.'
);
header('Content-Type: application/json');
echo json_encode($response);
// 在jQuery中的示例代码
$.ajax({
url: 'your-api-url',
method: 'POST',
data: formData,
success: function(response) {
if (response.status === 'success') {
// 提交成功的处理逻辑
console.log(response.message);
}
}
});
// 在PHP中的示例代码
$response = array(
'status' => 'error',
'message' => 'Form submission failed.'
);
header('Content-Type: application/json');
echo json_encode($response);
// 在jQuery中的示例代码
$.ajax({
url: 'your-api-url',
method: 'POST',
data: formData,
error: function(xhr, status, error) {
// 提交失败的处理逻辑
console.log(error);
}
});
请根据您的具体需求调整代码示例中的URL、数据和其他参数。