简体   繁体   中英

Wrong return data 1 instead 0 in ajax post data

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 :

data_featured返回1而不是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!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM