简体   繁体   English

错误的返回数据1代替ajax post数据中的0

[英]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:

$.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: 我的HTML数据如下:

<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: ==> HTML中的数据功能通常显示0,就像它应该这样:

数据功能

But when I submit button Ajax data job_featured returns 1 instead 0 : 但是当我提交按钮Ajax数据job_featured返回1而不是0:

data_featured返回1而不是0

tried change .attr() to .data() didn't help. 尝试将.attr()更改为.data()并没有帮助。 When I set data-featured manually to 0 instead of PHP code, it is displays to 0 without problems. 当我将功能data-featured手动设置为0而不是PHP代码时,它将显示为0,没有问题。

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 ? 您是否注意到job_id75而不是78

$('a.confirm') gets all matching links with that class, not just the one you clicked. $('a.confirm')获得$('a.confirm')所有匹配链接,而不仅仅是您单击的那个。 You may need to use var link = $(this); 您可能需要使用var link = $(this); at the start of your event handler to correctly handle the link. 在事件处理程序的开头正确地处理了链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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