我正在使用JsonForm:https://github.com/joshfire/jsonform/wiki#wiki-开始
我正试图从外部.txt文件将表单架构加载到$('form').Jsonfrom()中
尝试使用ajax将其加载到我的.html文件中,将其放入javascript变量中,然后用click事件调用$('form').Jsonfrom()。
这是我的代码:
<script>
#Load in .txt to javascript variable using ajax
var stringData = $.ajax({
url: "schema.txt",
async: false
}).responseText;
#check that file is loaded correctly .- have check this works.
#alert(stringData);
#on clicking of a piece of text in a <p> wrapper call jsonForm function.
$(document).ready(function(){
$("p").click(function(){
$('form').jsonForm(stringData )
});
});
</script>
我在firebug中得到的错误是:
"类型错误:this.formDesc.schema未定义"
&我的堆栈跟踪是这样的:
http://tinypic.com/r/2uiybo4/5
我想我的问题可能是在用ajax加载.txt文件的过程中。
但是,如果我在中进行注释:alert(stringData)。for的方案显示得很完美。
就像这样:http://tinypic.com/r/2ynl9qh/5
该方案也没有问题,因为我已经尝试将其直接放入$('form').Jsonfrom("here")
&它运行良好。
设法解决了这个问题。
必须使用模板语言(jinja2)而不是ajax,才能将表单模式放入html文档中。。这样json表单(一个jquery表单构建器)在页面加载时会在一个完整的html文档上执行。
傻!
希望这能有所帮助。