Mar*_*per 0 javascript ajax jquery
我目前正在尝试让我的Ajax将一些信息从HTML表单发布到PHP表单中.
那么,现在我已经制作了差异代码,应该在"ajax.comment.php"页面打印出来,告诉发生了什么.
就像成功与否一样.
我现在想制作我的ajax,检查打印的html是什么.然后处理...就像if(打印HTML =="1"){然后做某事}.
我怎样才能做到这一点?
我的以下javascript是:
var name = document.comment.name.value;
var email = document.comment.email.value;
var website = document.comment.website.value;
var message = document.comment.message.value;
var id = document.comment.id.value;
$.ajax({
type: "POST",
url: "ajax.addcomment.php",
data: "name="+name+"&email="+email+"&website="+website+"&message="+message+"&id="+id,
beforeSend: function() {
// Action before sending data
},
success: function(returned_html) {
// Action after sending data, where the returned_html var is the returned html text by the php
}
});
Run Code Online (Sandbox Code Playgroud)
在你的success功能中,试试这个:
success: function(returned_html) {
var the_result = $.trim(returned_html);
if(the_result == '1')
{
// Do whatever you wanted here.
}
else
{
// Do something else here...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
119 次 |
| 最近记录: |