weixin_33728268 2015-03-03 18:55 采纳率: 0%
浏览 28

从Ajax调用PHP函数

I'm new to AJAX, and can't get a php function to run.

The AJAX post request is working as it should, here's the code:

function thumbs(i) {
    $('.thumbs-up' + String(i)).click(function(){
        $(this).addClass('up');
        $.ajax({
            type:"POST",
            url:"item.php",
            data:'act=up&function' + String(i) + '=true&user=' + email,
            success: function(){
            }
        });
    });

for (var i = 1; i <= count; i++) {
    thumbs(i);
}

The above works, I receive all the correct values.

Then the PHP code that should run is here:

for ($i = 1; $i <= $count; $i++) {

    if ($_POST['function' . $i] == 'true') {
        //code that should run but does not
    }
}

The count variable is the same. Is there anything wrong here?

  • 写回答

1条回答 默认 最新

  • weixin_33701294 2015-03-03 18:58
    关注

    You're using get parameters instead of sending post parameters. See the example in the docs

    $.ajax({
      type: "POST",
      url: "some.php",
      data: { name: "John", location: "Boston" }
    })
    .done(function( msg ) {
        alert( "Data Saved: " + msg );
    });
    
    评论

报告相同问题?