4

Can anyone please point out exactly what I am doing wrong, I am trying to make a php call when a selected value is changed.

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

查询代码

// 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';


?>

感谢您的帮助和时间!

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

4

4 回答 4

4

尝试这个:

$('#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);
        }
    });
});
于 2013-06-20T22:21:03.870 回答
1

尝试这个

$('#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");
        }
    });
});
于 2013-06-20T22:21:00.200 回答
1

您应该使用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');
    });
});
于 2013-06-20T22:32:47.520 回答
0

你可以像这样测试一下......

// 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);
    })
});
于 2013-06-20T22:23:12.947 回答