jQuery $.ajax() executed twice?

后端 未结 4 1882
一个人的身影
一个人的身影 2020-12-19 09:41

Here is a button:


and a bound event:

$(\"#addToCart\         


        
相关标签:
4条回答
  • 2020-12-19 09:50

    This is happening because of this: http://httpd.apache.org/docs/2.0/mod/mod_dir.html#directoryslash

    Nohing to do with your javascript, this is pure Apache wizardry.

    Of course, as pointed out in other answers, you should add a slash after "add" because "add" is obvisouly a folder, not a file.

    0 讨论(0)
  • 2020-12-19 09:53

    The header has the clues you need.

    Your request to '/cartManager/add' is being forwarded to '/cartManager/add/' (notice the ending forward slash).

    Replace your ajax call with

    $.ajax({
                        url: '/cartManager/add/',
                        data:{
                            pictureId: currentImageId,
                            printSize: $("#size option:selected").val(),
                            paperType: $("#paperType option:selected").val(),
                            quantity: 1
                        },
                        success: function(){
                            $("#modal").html("<h1>ОК</h1><p>Closing in a sec</p>").delay(1000);
                            $("#modal").overlay().close();
    
                        }
                    });
    
    0 讨论(0)
  • 2020-12-19 09:55

    There's nothing wrong per-se, but you should add the trailing slash to /cartManager/add yourself.

    What's happening is that the web server is sending a 301 redirect to the AJAX client with a new URL, so it issues a new request to the proper URL (i.e. with the trailing slash).

    0 讨论(0)
  • 2020-12-19 09:58
    Status Code:301 MOVED PERMANENTLY
    

    No, your JavaScript is not causing this. It looks like your server is redirecting /cartManager/add to /cartManager/add/. Since the server wants a trailing slash, why not just add it and avoid the redirect?

    0 讨论(0)
提交回复
热议问题