我正在使用 Ajax 调用 PHP 文件来处理来自提交的文件。我的 JQuery 表单验证检查变量的值以确定是否提交表单或返回 false 并显示错误消息。如何在成功时将 JQUERY 变量和值从我的 PHP 文件返回到当前脚本?
我的 JQuery 和 Ajax:
$.ajax({
type: "POST",
url: "validate.php",
data: dataString,
success: // what do I do here? {
}
});
我是否只在我的 PHP 页面上输出一个脚本,然后返回 HTML?
最佳答案
$.ajax({
type: "POST",
url: "validate.php",
data: dataString,
//you can use json data, it will be easier to tranfer complex data
dataType: "json",
success: function(data) {
//the data will contain the return result
//for example you have an error message in following format
//{error:'some error has been occured'}
if(data.error)
alert(data.error);
}
});
关于javascript - 使用 Ajax 返回 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21128726/