json 请求和 django 响应
为什么我在发送 json 请求后没有得到服务器的响应,我在做什么错误的
$("#chat").submit(function(){
// If user clicks to send a message on a empty message box, then don't do anything.
alert($("#msg").val());
alert(url);
if($("#msg").val() == "") return false;
$.post(url,
alert('22'),
{
time: timestamp,
action: "postmsg",
message: $("#msg").val()
},
function(load) {
$("#msg").val(""); // clean out contents of input field.
// Calls to the server always return the latest messages, so display them.
processResponse(payload);
},
'json'
);
Django 视图函数:
def ajaxcall(request):
#I have tried both the return statements and there are no exceptions since see the logging
#logging.debug(response)
#return HttpResponse(simplejson.dumps(response), mimetype='application/javascript')
#return response
Why dont i get a response from the server after sending the json request,what am i doinfg wrong
$("#chat").submit(function(){
// If user clicks to send a message on a empty message box, then don't do anything.
alert($("#msg").val());
alert(url);
if($("#msg").val() == "") return false;
$.post(url,
alert('22'),
{
time: timestamp,
action: "postmsg",
message: $("#msg").val()
},
function(load) {
$("#msg").val(""); // clean out contents of input field.
// Calls to the server always return the latest messages, so display them.
processResponse(payload);
},
'json'
);
Django views function:
def ajaxcall(request):
#I have tried both the return statements and there are no exceptions since see the logging
#logging.debug(response)
#return HttpResponse(simplejson.dumps(response), mimetype='application/javascript')
#return response
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您的 jQuery POST 语法是否正确。
这是一个例子:
记住这里的顺序很重要。第二个参数预计是数据,但您的第二个参数似乎是对警报的调用。
如果您要提交表单或表单中的某些内容,则需要序列化表单元素。
为了更好地控制这个过程,您可能需要尝试使用 jQuery 中较低级别的 $.ajax() 函数。
I'm not sure your syntax for the jQuery POST is correct.
Here's an example:
The order here is important to remember. The second argument is expected to be the data, but your second argument appears to be a call to alert.
If you're submitting a form, or something from a form, you need to serialize the form element.
To get more control over this process you might want to try using the lower-level $.ajax() function in jQuery.