使用jQuery AJAX传递变量无法在Firefox和Safari中运行,可在Chrome中使用

时间:2022-10-07 16:12:42

html

<li><a class="download-link" href="<?php echo $path_data;?>">Download</a></li>

ajax

$(function(){
        $('.download-link').click(function() {
            var wall_id = <?php echo $wall_id;?>;   //store current wall id
            $.ajax({
                type    : 'GET',
                url     : 'functionality/php/download_count.php',
                data    : { wall_id : wall_id }
            });         //ajax end
        });             //live end
    });                 //function end

php (download_count.php)

<?php

    $wall_id = preg_replace("#[^0-9]#", "", $_GET['wall_id']);

    //increment download count query
    $increment_downloads = $connectDB->prepare("UPDATE database.table SET
                          downloads = downloads + 1 WHERE wall_id = ?");
        $increment_downloads->bind_param('i', $wall_id);
        $increment_downloads->execute();
    ?>

I'm trying to update download count when the Download link is clicked. But the downloads in by table don't increment. Not sure where the problem is. Need help.

我在点击下载链接时尝试更新下载次数。但是表中的下载量不会增加。不确定问题出在哪里。需要帮忙。

Update: Above code NOT working in Firefox and Safari, but works fine with Chrome.

更新:上面的代码不适用于Firefox和Safari,但适用于Chrome。

2 个解决方案

#1


0  

you are missing quotes around the value of var wall_id

你缺少var wall_id值的引号

var wall_id = <?php echo $wall_id;?>;  

should be

 var wall_id = "<?php echo $wall_id;?>"; 

#2


0  

change your ajax

改变你的ajax

    $('.download-link').click(function(){
        var wall_id = <?php echo $wall_id;?>;   //store current wall id
        $.ajax({
            type    : 'GET',
            url     : 'functionality/php/download_count.php',
            data    : { wall_id : wall_id }
        });     //ajax end
    }); 

to

    $.get( "functionality/php/download_count.php", { wall_id : wall_id } )
        .done(function( data ) {
        alert( data );
    });

then add this to the end of you php script

然后将此添加到PHP脚本的末尾

    echo $_GET['wall_id'];

then let me know if you are getting the right value

如果你得到了正确的价值,请告诉我

#1


0  

you are missing quotes around the value of var wall_id

你缺少var wall_id值的引号

var wall_id = <?php echo $wall_id;?>;  

should be

 var wall_id = "<?php echo $wall_id;?>"; 

#2


0  

change your ajax

改变你的ajax

    $('.download-link').click(function(){
        var wall_id = <?php echo $wall_id;?>;   //store current wall id
        $.ajax({
            type    : 'GET',
            url     : 'functionality/php/download_count.php',
            data    : { wall_id : wall_id }
        });     //ajax end
    }); 

to

    $.get( "functionality/php/download_count.php", { wall_id : wall_id } )
        .done(function( data ) {
        alert( data );
    });

then add this to the end of you php script

然后将此添加到PHP脚本的末尾

    echo $_GET['wall_id'];

then let me know if you are getting the right value

如果你得到了正确的价值,请告诉我