使用jquery表单插件上传文件
我有一个输入类型=“文件”的表单。它使用ajax(插件jquery form)提交。 服务器返回 json 响应。 json 数据中有 html 标签:
{"logs":"<span>vfdvf<\/span>","errors":"<span><\/span>"}
但是当插件收到此响应时,它传输的
{"logs":"<span>vfdvf<\/span>","errors":"<span><\/span>"}</span></span>
不是正确的 json。我该如何修复它?如果表单中没有 input type="file" 元素,则一切正常。
这里是 JS
$('#edit_ext_table_form').ajaxForm({
dataType: 'html',
success: function(responseText) {
console.log(responseText);
},
error: function(request) {
var responseText=request.responseText;
console.log(responseText);
}
}
这里是 PHP
$a = array(
'logs' => '<span>vfdvf</span>',
'errors' => '<span></span>',
);
exit(json_encode($a));
i have a form with input type="file". it submits using ajax (plugin jquery form).
Server returns json response. There are html tags in json data:
{"logs":"<span>vfdvf<\/span>","errors":"<span><\/span>"}
but when plugin gets this response it transferred in
{"logs":"<span>vfdvf<\/span>","errors":"<span><\/span>"}</span></span>
it is not correnct json. How can i fix it? If there is no input type="file" element in form, all works fine.
Here is JS
$('#edit_ext_table_form').ajaxForm({
dataType: 'html',
success: function(responseText) {
console.log(responseText);
},
error: function(request) {
var responseText=request.responseText;
console.log(responseText);
}
}
Here is PHP
$a = array(
'logs' => '<span>vfdvf</span>',
'errors' => '<span></span>',
);
exit(json_encode($a));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您无法通过 ajax 提交文件,Html 5 具有更好的文件上传功能。但在较旧的浏览器中这是不可能的。不确定这是否正是破坏你的 json 的原因,但你的最终目标是无法实现的。
You cannot submit a file via ajax, Html 5 has much better file upload capabilities. But in older browsers its not possible. Not sure if thats exactly what is breaking your json, but your end goal is unachievable.