Ajax Form 'POST' result as 'GET'
Hello everyone, I'm learning some Jquery on a website and I was trying to understand how does it work ajax used with forms. I created this simple form which should send all the data using POST:
- <!DOCTYPE html>
- <html>
- <head>
- <title>Ajax Form</title>
- <script src="http://code.jquery.com/jquery-3.0.0.js"></script>
- </head>
- <body>
- <div class="row">
- <div class="col-md-12">
- <h1>Ajax Form</h1>
- <form>
- <label for="destinatio">Destinazione</label>
- <select name="destination" id="destionation">
- <option value="londra">londra</option>
- <option value="parigi">parigi</option>
- <option value="roma">roma</option>
- </select>
- <br>
- <input type="number" name="day">
- <br>
- <input type="submit" value="book">
- </form>
- <div class="tour"></div>
- </div>
- </div>
- </body>
- <script type="text/javascript">
- $(document).ready(function(){
- $($('form').attr('action')).on('submit', function(event){
- event.preventDefault();
- var form = $(this);
- $.ajax('/book.html', {
- type: 'POST',
- contentType: 'application/json',
- dataType:'json',
- data: form.serialize(),
- success: function(result){
- var msg = $('<p></p>');
- //msg.append()
- $('.tour').html(result);
- console.log(this.data)
- }
- });
- });
- });
- </script>
- </html>
The Problem is that if I look inside the Chrome developer tools, inside the Network panel, when I sumbit the form I see that:
-
Request URL:
-
Request Method:
GET
Also on the search bar at the top when I submit something i see the url changes like the data it's sent using GET like this:
Does anyone know why?