脚本宝典收集整理的这篇文章主要介绍了php – json数据返回无效标签错误,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
上传文件时,我不断收到此错误消息:SyntaxError:invalid label
这是我的JS脚本:
jquery('.uploadImage').live('click',function() { ajaxFileUpload(); }); (...) function ajaxFileUpload(){ jQuery.ajaxFileUpload({ url:'../wp-content/plugins/wp-filebrowser/uploader.PHP',secureuri:false,fileElementId:'uploaDFile',dataTyPE: 'json',success: function (data,status){ if(typeof(data.error) != 'undefined'){ if(data.error != ''){ alert(data.error); }else{ alert(data.msg); } } },error: function (data,status,e){ alert(data + ' - ' + status + ' - ' + e); } } ) return false; }
我的PHP脚本工作(在使用JSON / jquery之前测试过),但我的PHP文件中的json输出肯定有问题.我尝试了两种方法.
我正在使用json_encode来格式化输出.这是我的一些PHP代码:
(...) // Error message is at this stage empty. move_uploaded_file($_FILES["file"]["tmp_name"],$uploadfile); $respons = $_FILES["file"]["name"]._e(' successfully uploaded'); $data = array( "error"=> $error,"msg"=> $respons ); echo json_encode($data);
UPDATE
事实证明,我使用Worpdress的_e()来支持多语言.问题是_e()echo的内容和因此混淆了JSON响应.一旦我切换到__()就行了.
谢谢你帮助我这个笨蛋们.
以上是脚本宝典为你收集整理的php – json数据返回无效标签错误全部内容,希望文章能够帮你解决php – json数据返回无效标签错误所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。