我有这个项目,除了两件事外,他似乎工作得很好。当我执行POST REQUEST(之前的一些 ajax 调用之后)时:
首先:我在 Chrome 版本 25.0.1364.172 上得到了一个error: [Errno 32] Broken pipe
,但一切似乎仍然正常。
第二:在 Firefox 19.0.2 中没有任何反应.. 它csrfmiddlewaretoken
在我的 url 中添加并显示 200 并使用我的 javascript 操作重新加载页面,但在 django 端似乎实际上没有做任何事情。
代码:
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="appName">App Name</label>
<div class="controls">
<input type="text" id="appName" placeholder="App Name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="appDescription">App Description</label>
<div class="controls">
<textarea id ="appDescription" placeholder="App Description" rows="3"</textarea>
</div>
</div>
<div class="form-actions">
{% csrf_token %}
<button type="submit" class="btn btn-primary" name="create" onclick="createCity('create','user')">Create</button>
</div>
</form>
javascript:
$.post(url, { city_id : city_id ,type : type, city: cityStr, pois: poisStr, poisdelete: poisDeleteStr, kmz: kmzStr,kmzdelete : kmzDeleteStr,limits : limitsStr, limitsdelete : limitsDeleteStr, area_name : area_nameStr , action : actionStr , imageReplace : imageReplaceStr}, function(data,status) {
if (data=='city_already_exists')
alert(data);
else {
/*var username=window.location.pathname.split("/");
window.location = "/"+username[1]+"/smarturbia/cities";*/
alert(data);
location.reload(); //otherwise does not work with firefox
}
});
姜戈:
class CreateCityView(LoginRequiredMixin, JSONResponseMixin, CheckTokenMixin, CurrentUserIdMixin, View):
@method_decorator(csrf_protect)
def dispatch(self, *args, **kwargs):
return super(CreateCityView, self).dispatch(*args, **kwargs)
def post(self, request, *args, **kwargs):
...
return self.render_json_response(city_json)
一个帖子如何在 chrome 中而不是在 Firefox 中工作?我应该怎么做才能让它同时工作?