Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question