【发布时间】:2016-04-09 16:16:24
【问题描述】:
我正在 django 上写页面。不工作 jquery Post 请求。单击#encrypt 后没有任何反应。我尝试通过 $.get、$.ajax 提出请求 - 没有。在$.post之前一切正常
home.html:
$(document).ready(function() {
$("#encrypt").click(function () {
var postData = {
text: $("#input-box").val(),
rotate: $("#rotate").val()
};
$.post('encrypt', postData, function (data){
alert(data);
});
});
});
views.py:
def home(request):
return render_to_response("home.html", {})
def encrypt(request):
text=request.POST["text"]
#some manipulation with text
return render_to_response("home.html", {'text': text})
urls.py:
urlpatterns = [
url(r'^$', caesar.views.home, name="home"),
url(r'^encrypt$', caesar.views.encrypt, name="encrypt")
]
【问题讨论】:
-
您能否用您已经尝试过的一些方法更新您的问题?如果您向事件处理程序添加断点,您是否看到它被命中/它到达了多远?
-
看起来有语法错误。 “函数数据{”应该是:“函数(数据){”。
-
只是文本错误。在我的代码中不是
-
嗯,您的网址好像有误。尝试将 $.post('encrypt', 更改为 $.post('/encrypt',
-
现在可能有效,但是 alert(data);显示此页面的 html 代码。有什么问题?