weixin_33743880 2015-10-19 14:08 采纳率: 0%
浏览 105

Ajax POST执行两次

I can't unsderstand why this Ajax POST is executed twice. I saw in other threads that the problem is that the browser is adding '/' tp my URL but not in my case. This my js:

var Profile = function (params) {
    this.profilecontainer = params.profilecontainer;
    this.profileManagementURL = params.profileManagementURL;
    this.orderURL = params.orderURL;
    this.editProfile();
};


Profile.prototype.editProfile = function ()
{
    var self = this;
    $('.' + self.profilecontainer).on('submit',"form", function (e)
    {
       e.preventDefault();

       $.ajax({
           type: 'POST',
           url: self.profileManagementURL,
           data: $(this).serializeArray(),
           success: function (data) {
           },
           error: function (jqXHR)
           {
            }
    });

});
};

This is my Twig:

{% block content %}
<div class="container content">
            <div>
                <div>
                    {{ render(path('profile_management')) }}
                </div>
            </div>
</div>
{% endblock %}

{% block javascripts %}
<script src="{{ asset('bundles/frontend/js/Profile.js') }}"></script>
<script type="text/javascript">

    $(function () {
        // Variables twig à passer aux scripts js
        var params = {
            profileManagementURL: '{{ path('profile_management') }}',
            orderURL: "{{ path('order_in_progress') }}",
            profilecontainer: 'container'
        };
        var oProfile = new Profile(params);
    });

</script>
{% endblock %}

Now this is my controller:

/**
 * @Route("/profile_management", name="profile_management")
 *
 * @param Request $poRequest Objet requête
 *
 * @return Response
 */
public function profileManagementAction()
{
    $oForm     = $this->createForm(ProfileForm());

    $oForm->handleRequest($poRequest);
    if ('POST' == $poRequest->getMethod())
    {
        if ($oForm->isValid())
        {  
        }
    }

    return     $this->get('templating')->renderResponse('FrontendBundle:Profile:userForm.html.twig', array(
                'form' => $oForm->createView(), $oResponse
                    ), $oResponse
    );
}

I have done a lot functions using the same format of code but I don't know what is special with this one.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题