我一直在尝试让一些Ajax的东西在我的Django应用程序中工作,但它一直很困难,因为由于某些原因语法和类型错误不会导致服务器崩溃,并且默默地失败。这怎么可能?Django开发服务器没有从Ajax请求服务错误
的JavaScript(jQuery的):
add_foo = function() {
var numfoos = $("div#foos_container > div.foo").length + 1;
var foo_id = numfoos + "-foo";
var div = $("<div></div>").attr("id",foo_id).addClass("foo");
div.load("http://localhost:8000/ajax/get/url/");
div.appendTo("div#foos_container");
};
的Python:
def ajax_add_foo(request):
print request.session['editing_foos'].keys()
keys = request.session['editing_foos'].keys()
if len(keys) == 0:
next_key = 1
else:
next_key = max([ id_from_prefix(key) for key in keys ])
print next_key
form = FooForm(prefix=next_key)
print next_key
request.session['editing_foos'].update({create_prefix(FooForm, next_key) : -1 }) # This foo is new and has no pkey
print request.session['editing_foos']
return render_to_response('bar/foo_fragment.html',
{'fooform' : fooform, },
context_instance=RequestContext(request))
如何发送Ajax请求的JavaScript代码样子?如何接受Ajax请求的Python代码看起来像?你能否更新它并将其发布在你的问题中。 – 2009-12-22 09:40:36
如果您尝试调试ajax的JavaScript端,请尝试:http://getfirebug.com/ – miku 2009-12-22 09:40:53
我添加了代码:-) – SapphireSun 2009-12-22 09:48:24