weixin_33690963 2015-04-05 18:01 采纳率: 0%
浏览 137

Ajax未发送请求

I have been struggling on this simple problem for pretty long already, yes I tried to google for answer though with no luck, the problem is that my ajax request doesn't even send a thing, so I guess it has something to do with the syntax though it looks perfectly fine to me:

$(window).on('load',function()
{
    $("#unfriend_user > p").click(function()
    {
        $.ajax(
        {
            url: "php_includes/remove_friend.php", 
            type: "POST",
            data: 
            {
                user_1 : <?php echo $logged_id ?> ,
                user_2 : <?php echo $page_user_id ?>,
                user_username : <?php echo $logged_username ?>,
                user_password : <?php echo $logged_password ?>
            },
            success: function(data)
            {
                alert(data);
            }
        });
    });
});

All php echoed variables have values.

The problem came up after I added these two lines:

user_username : <?php echo $logged_username ?>,
user_password : <?php echo $logged_password ?>

If I remove these two lines and "," everything works just fine.

  • 写回答

2条回答 默认 最新

  • weixin_33724046 2015-04-05 18:05
    关注

    If you look at your rendered HTML ("View Source" in the browser), you'll see that your javascript looks something like:

    data: 
        {
            user_1 : 1 ,
            user_2 : 2,
            user_username : someusername,
            user_password : somepassword
       },
    

    Since those are strings (I'm assuming), you need to quote them:

    data: 
        {
            user_1 : <?php echo $logged_id ?> ,
            user_2 : <?php echo $page_user_id ?>,
            user_username : "<?php echo $logged_username ?>",
            user_password : "<?php echo $logged_password ?>"
        },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号