Yet another JSON jQuery error
My Server returns:
{"content":"<div>\n <form style=\"width: auto\" id=\"pictureUploadForm\" method=\"POST\" enctype=\"multipart/form-data\" action=\"https://localhost/simmapp/action/admin.CMSAction\">\n <label for=\"fileUpload\">Choose File : </label><br/>\n <input type=\"file\" name=\"fileUpload\" /><br/>\n <input type=\"hidden\" name=\"eventSubmit_uploadFile\" value=\"T\"/>\n <span class=\"tip\">Warning this will refresh page, potentially losing unsaved work.<br/>\n </form>\n <button class=\"button\" onclick=\"CMSManager.submitUpload()\">Upload File</button>\n</div>"}
According to JSONLint that's valid, and another JSON validator (http://jsonformatter.curiousconcept.com/) says the same.
So why does jQuery.getJSON fail?
I'm about ready to get rid of jquery and go back to using jxs.js as it worked fine for years. jQuery is a PITA.
jx.load(link.getURL(), function(data){
PopUp.add({
content:data.content,title:"Upload File",
closeable:true})
}, 开发者_如何学JAVA"json","GET");
Works
$.getJSON(link.getURL(), function (data) {
PopUp.add({content:data.content,title:"Upload File",closeable:true})
});
Doesn't. I realize jx doesn't do any JSON parsing(it just uses eval). I've been trying to migrate over to jQuery, but it's been painful.
The jQuery section fails silently, which is generally assumed to be a parse error. But I can't see the problem.
{"content":"<div><form style=\"width: auto\" id=\"pictureUploadForm\" method=\"POST\" enctype=\"multipart/form-data\" action=\"http://localhost/simmapp/action/admin.CMSAction\"><label for=\"fileUpload\">Choose File : </label><br/><input type=\"file\" name=\"fileUpload\" /><br/><input type=\"hidden\" name=\"eventSubmit_uploadFile\" value=\"T\"/><span class=\"tip\">Warning this will refresh page, potentially losing unsaved work.<br/></form><button class=\"button\" onclick=\"CMSManager.submitUpload()\">Upload File</button></div>"}
Works, can you spot the difference? \t Tabs, apparently in addition to newlines, parseJSON doesn't like tabs either.
精彩评论