A
A
Andrey54Gromov2021-07-30 17:41:22
AJAX
Andrey54Gromov, 2021-07-30 17:41:22

What needs to be specified in order for the ajax script to work correctly?

Hello.
The code should update the variable on the page without reloading it.

Where to add this variable? subtotal

<button type="button" id="button" class="btn btn-primary" >Кнопка</button>

$("#button").click(function(){ // click function fired

var subtotal = $("#subtotal").val()
var dataString = 'subtotal=' + subtotal;

$.ajax({ // ajax post
    type: "POST",
    url: "index.php", // post data to this URL
    data: dataString,
    cache: false,
    success: function(html){ // this is where you can set a success callback
       $("#subtotal").val("You're new value");
    }
});
return false; // this tells the page not to refresh

)};​

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aricus, 2021-08-02
@Aricus

Data in ajax must be sent in the wrong format.
data: {subtotal:subtotal}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question