Jquery ajaxForm没有';不创建html元素
我的剧本怎么了。 它不会在ajax上创建html元素成功吗 以下是脚本:Jquery ajaxForm没有';不创建html元素,jquery,ajax,json,Jquery,Ajax,Json,我的剧本怎么了。 它不会在ajax上创建html元素成功吗 以下是脚本: $('.ajaxForm').ajaxForm({ dataType : "json", success : function(data){ if(data.msg=='ok'){ setTimeout("fnChangePage('/login')",5000); }else{
$('.ajaxForm').ajaxForm({
dataType : "json",
success : function(data){
if(data.msg=='ok'){
setTimeout("fnChangePage('/login')",5000);
}else{
$(".dialog p").html(data.msg);
$(".dialog").dialog({
title : "Error!"
});
}
}
});
{"msg":"<ul><li>Repeat Password!<\/li><li>Employee not found!<\/li><\/ul>"}
我的json的输出如下:
$('.ajaxForm').ajaxForm({
dataType : "json",
success : function(data){
if(data.msg=='ok'){
setTimeout("fnChangePage('/login')",5000);
}else{
$(".dialog p").html(data.msg);
$(".dialog").dialog({
title : "Error!"
});
}
}
});
{"msg":"<ul><li>Repeat Password!<\/li><li>Employee not found!<\/li><\/ul>"}
如果以下行是要创建html元素的行:
$(".dialog p").html(data.msg);
然后需要data.msg
来包含包含html标记的元素。因此,您需要将服务器端代码更改为输出
,而不是
和
。也就是说,JSON输出应该是:
{"msg":"<ul><li>Repeat Password!</li><li>Employee not found!</li></ul>"}
{“msg”:“- 重复密码!
- 找不到员工!
”}
如果由于某种原因无法在服务器端进行更改,可以在使用之前在JS中替换它:
$(".dialog p").html( data.msg.replace(/>/g,">").replace(/</g,"<") );
$(“.dialog p”).html(data.msg.replace(//g,“>”).replace(//g,“您在console.log中遇到了什么错误?@jQuerybeast,没有错误..它只是像这样输出- 重复密码!