I want to send a ajax post request to the page when clicked.My code
$(document).on('click', '#datadel', function(num) {
$.ajax({
url:'https://localhost/ajax/ajax_img.php?act=datadel',
type: 'POST',
data: {'num':num},
success: function(infa){
$('#img-loag-scrin').html(infa);
}
});
});
html code
<span id="datadel" class="sf_button_red" value="50">O`chirish</span>
then the value in the span should be sent as a post. what’s wrong with the code I wrote
2
Answers
The
span
element doesn’t have a value attribute, you could prefix it withdata-
and get the value withattr
ordata
method.Example:
HTML:
Demo:
The
span
tag doesn’t have avalue
attribute. You can replace thevalue
attribute with anydata
attribute, likeand the value can be retrieved using the code