1
是新來jquery.I我在Django使用jQuery做一些Ajax。
$(document).ready(function() {
$.getJSON('/jsonserver/', function(json){
alert("JSON Data: " + json);
});
以上的jQuery爲我工作。當我把同樣的點擊功能按鈕,它調用URL成功,但警報不會顯示。
$(document).ready(function() {
$('#save').click(function(){
$.getJSON('/jsonserver/', function(json){
alert("JSON Data: " + json);
});
});
});
<form method ="POST" method =/jqueryserver/ name ="form1" id ="form1">
<input type= "submit" id = "save" name ="save" value ="Save" />
</form>
view.py
def jsonserver(request):
print "...jsonserver..."
json = simplejson.dumps('hello world!')
return HttpResponse(json, mimetype = 'application/json')
感謝@blockhead,爲您快速回答 – Jisson
這個問題是一個問題,即使按鈕沒有一個提交按鈕....和e.preventDefault解決了它... –