2

私の ajax リクエストはホスト上で完璧な方法で実行されますが、アプリケーションがサーバーにインストールされるたびに、すべてのリクエストのステータスが「301 永久に移動されました」になります。

これをデバッグするのにすでに3日かかりましたが、仕方がありません。なぜこれを取得しているのかわかりません。Symfony2 を使用しています。

これはサーバー側のリクエストです:

$('#edit').click(function () {
    var $validEmail = $('#mail').validator({
        type: 'error',
        rules: [{
            control: 'email',
            message: 'Format invalide'
        }]
    });
    var $validpost_code = $('#post_code').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Code postal obligatoire'
        }]
    });
    var $validRs = $('#rs').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Raison sociale obligatoire'
        }]
    });
    var $validAddr = $('#addr').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Adresse obligatoire'
        }]
    });
    var $validPhone_number = $('#phone_number').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Tel obligatoire'
        }]
    }) && $('#phone_number').validator({
        type: 'error',
        rules: [{
            control: 'phone',
            message: 'Format requise mask: +33 # ## ## ## ##'
        }]
    });

    var $validCountry = $('#country').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Ville obligatoire'
        }]
    });
    var $validTown = $('#town').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Pays obligatoire'
        }]
    });
    var $valid3897 = $('#3897').validator({
        type: 'error',
        rules: [{
            control: 'required',
            message: 'Forme juridique obligatoire obligatoire'
        }]
    });
    if ($validEmail && $validpost_code && $validRs && $validAddr && $validPhone_number && $validTown && $valid3897 && IsPosInteger($('#post_code').find('input').val())) {
        var data = {
            name: $('#name').find('input').val(),
            id: "{{client.id}}",
            post_code: $('#post_code').find('input').val(),
            rs: $('#rs').find('input').val(),
            address: $('#addr').find('input').val(),
            email: $('#mail').find('input').val(),
            effectif: $('#efectif').find('input').val(),
            turnover: $('#turnover').find('input').val(),
            siteWeb: $('#site').find('input').val(),
            phone_number: $('#phone_number').find('input').val(),
            country: $('#country').find('input').val(),
            town: $('#town').find('input').val(),
            fax: $('#number').find('input').val(),
            kbis: $('#bis').find('input').val(),
            vat: $('#vat').find('input').val(),
            legal_form: $('#3897').find('select').val(),
            active: $('#active').attr('checked'),
            groupe: $('#groupe').find('input').val(),
            business_sector: $('#sa').find('input').val()
        };
        $("#site_content").block();
        $.ajax({
            url: "{{url('Update_client')}}",
            type: "POST",
            dataType: 'json',
            data: {
                data: ODEANCE.toJson(data)
            },
            success: function (updateResponse) {
                if (updateResponse) {
                    $("#site_content").unblock(),
                    jAlert('Modification effectuée  avec sucées ', 'Modification') //,
                    //document.location=document.location
                }
            }
        });
    } else {
        jAlert('Veuillez vérifier les formats de vos champs', 'Modification');
    }
});

そしてここにコントローラーのメソッドがあります:

public function updateClientAction() {
    try {
        //Getting sended data 
        $data = $this->getRequest()->get('data');
        $data = \json_decode(\stripslashes($data));
        $spi = $this->get('spi');
        $clientManager = $spi->getClientManager();
        $updateResponse =($clientManager->update($data) == true ) ?  1 : 0;
        return new Response($updateResponse);
    } catch (\Exception $ex) {
        $updateResponse = 0;
        return new Response($updateResponse);
    }
}

リクエストのレスポンスが(リクエストの)元の場所に戻らないようです。

4

4 に答える 4

0

数日後、問題は修正されました。これはhttpリクエストとhttpsリクエストの間の競合だったので、この行でアプリケーションをhttps側に強制するだけです。security.yml

access_control:        
      - { path: ^/,role: ROLE_USER, requires_channel: https }

みんなありがとう^^

于 2013-01-29T13:42:39.343 に答える
0

これが他の人に役立つ場合-同じ問題があり、url()の代わりにpath()を使用して解決しました。url() を使用すると、呼び出しは http に転送されてから https にリダイレクトされ、これが 301 の原因となった可能性があります。path() を使用すると、呼び出しは直接 https に転送されました。

于 2015-11-15T20:34:21.140 に答える
0

routing.yml のパターンから末尾のスラッシュを削除します

于 2016-11-16T16:55:46.493 に答える
0
  1. 直接参照してみてください{{url('Update_client')}}
  2. {{url('Update_client')}}の出力が正しい場合は、HTML ソースを確認してください
于 2013-01-15T14:16:07.653 に答える