2

私は彼が2つのことを除いてうまく働いているように見えるこのプロジェクトを持っています。POST REQUESTを実行すると(以前にいくつかのajax呼び出しの後): 最初:error: [Errno 32] Broken pipe Chromeバージョン25.0.1364.172でを 取得しますが、すべてが正常に機能しているようです。2番目: 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
    }
});

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)

投稿はFirefoxではなくChromeでどのように機能しますか?両方で動作させるにはどうすればよいですか?

4

1 に答える 1

0

htmlのをに変更することで修正しました。小さな間違い、大きな問題。

于 2013-03-21T15:27:38.037 に答える