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 );
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码