Reputation: 1597
I have tried so many ways, research for half of day but could not figure out what could possibility wrong in my code, I have Ajax below:
$.ajax({
url: "http://<?php echo $DOMAIN_NAME?>/extensions/set_featured.php",
type: "post",
data: {
job_id: $("a.confirm").attr('data-jobId'),
title: $("a.confirm").attr('data-title'),
job_featured: $("a.confirm").data('featured')
},
success: function (response) {
// you will get response from your php page (what you echo or print)
}
my HTML data is below:
<a href="#" class="confirm" data-title="Ưu tiên việc làm này?" data-jobId="<?php echo $value['id']?>" data-featured="<?php echo $value['featured']?>">
==> data-featured in HTML displays 0 normally like it should:
But when I submit button Ajax data job_featured
returns 1 instead 0 :
tried change .attr()
to .data()
didn't help.
When I set data-featured
manually to 0 instead of PHP code, it is displays to 0 without problems.
I have no ideas what could possibility cause an issue in my code. Any advise would be very appreciated :(
Thank you very much in advance!!
Upvotes: 0
Views: 80
Reputation: 324750
Have you noticed that the job_id
is 75
and not 78
?
$('a.confirm')
gets all matching links with that class, not just the one you clicked. You may need to use var link = $(this);
at the start of your event handler to correctly handle the link.
Upvotes: 1