AJAX is not calling PHP?



有没有人可以指出我到底做错了什么,我正试图使一个php调用当一个选定的值被改变。

代码没有回显php文件中的信息。

JQUERY代码
// Skill sort on change
$('#order_by').on('change', function() {
    $.ajax({
        type: "POST",
        url: "sort_skill_be.php",
        data: {skill:this.value}  
    }).done(function(result){
        console.log(result)
    })
});
PHP代码

<?php
session_start();
$skill_sort = $_POST['skill'];
echo $skill_sort;
echo 'I got in here';

?>

感谢您的帮助和时间!

编辑:它现在工作正常,感谢所有的帮助!

试试这个:

$('#order_by').on('change', function() {
    var sk = $(this).val();
    $.ajax({
        type: "POST",
        url: "sort_skill_be.php",
        data: 'skill=' + sk,
        success: function(result) {
            alert(result);
        }
    });
});

试试这个

$('#order_by').on('change', function() {
    $.ajax({
        type: "POST",
        url: "sort_skill_be.php",
        data: {skill:$(this).val()},
        success: function(result){
            alert("done");
        },
        error: function(){
            alert("error");
        }
    });
});

您应该使用then而不是done http://promises-aplus.github.io/promises-spec/

$('#order_by').on('change', function () {
    $.post("sort_skill_be.php", {
        skill: $(this).val()
    }).then(function (result) {
        console.log(result);
    }).fail(function () {
        console.err('failed to fetch data');
    });
});

你可以这样测试…

// Skill sort on change
$('#order_by').on('change', function() {
    $.ajax({
        type: "POST",
        url: "sort_skill_be.php",
        data: {skill:this.value}  
    }).done(function(result){
      console.log('my results' + results);
    })
});