我希望可以在这里提出这个问题。我到处搜索,但找不到解决方案。
我在https://github.com/do-web/jTinder找到了一个名为jTinder的不错的js库

现在,我试图将喜欢或不喜欢的内容保存在mysql数据库和php中。但是很快我会放弃!我尝试了很多不同的代码,但实际上没有任何反应。
通常,我根本无法执行脚本。

有人能帮我吗?

$("#tinderslide").jTinder({
// dislike callback
onDislike: function (item) {
    // set the status text
    $('#status').html('Dislike image ' + (item.index()+1));


    },


// like callback
onLike: function (item) {
    // set the status text
    $('#status').html('Like image ' + (item.index()+1));
},
animationRevertSpeed: 200,
animationSpeed: 400,
threshold: 1,
likeSelector: '.like',
dislikeSelector: '.dislike'
});


getdata.php看起来像这样:

$link = mysqli_connect("127.0.0.1", "root", "", "vacation");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$liked = mysqli_real_escape_string($link, $_POST['like']);


$sql = "INSERT INTO destinations (like) VALUES ('$liked')";
if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}


mysqli_close($link);


阿贾克斯:

$.ajax({
  url: 'getdata.php',


  dataType: 'json',
  success: function(data)
  {
    var id = data[0];
    var name = data[1];

    var count = data[3];


    $('#output').html('like('+id+')');

  }

最佳答案

这段代码有很多问题,所以

在您的html文件中,当您未在php代码中返回任何内容时,数据来自ajax。所以你的代码应该像测试一样

$("#tinderslide").jTinder({
// dislike callback
        onDislike: function (item) {

            $.ajax({
                url: 'getdata.php',
                data: 'DATA_YOU_WANT_TO_SEND',
                dataType: 'json',
                success: function (data) {
                    console.log()

                    //$('#output').html('like(' + id + ')');

                }
            });
                // set the status text
            $('#status').html('Dislike image ' + (item.index()+1));


        },

// like callback
        onLike: function (item) {
            // set the status text
            $('#status').html('Like image ' + (item.index()+1));
        },
        animationRevertSpeed: 200,
        animationSpeed: 400,
        threshold: 1,
        likeSelector: '.like',
        dislikeSelector: '.dislike'
    });


并在php代码中
如果您没有从ajax发送数据,那么您将像在其中插入如何在php文件中获取发布数据。

关于javascript - jTinder保存到数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36897909/

10-12 21:51
查看更多