Django Post request可以在chrome上工作,但不能在firefox上工作

Django Post request works with chrome but not with firefox

本文关键字:工作 但不能 firefox Post request Django chrome      更新时间:2023-09-26

我有这个项目,似乎他工作得很好,除了2件事。当我做一个POST请求(之前一些ajax调用后):第一:我得到一个error: [Errno 32] Broken pipe在我的Chrome版本25.0.1364.172,但一切似乎工作得很好。秒:在firefox 19.0.2什么也没发生。它在我的url中添加了csrfmiddlewaretoken,并显示了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
    }
});
Django:

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中??我该怎么做才能让它在两者上都起作用呢?

通过更改html中的to来修复它。小错大问题1 .

相关文章: