weixin_33717298 2016-01-15 01:34 采纳率: 0%
浏览 20

ajax“发布”请求失败

I am using ajax for the first time and passing data to another file using ajax request. The request goes through if I pass it using get which is by default but the moment I change it to post it does not work.

$.ajax({
            type:'POST',
            url:'pageAjax2.php',
            data:'name='+name,
            success: function(data){
                $('#content').html(data);
            }
      })

If I remove the type:'POST'; everything works but if have it in the code nothing works . Can someone please help me with this.

  • 写回答

2条回答 默认 最新

  • weixin_33743661 2016-01-15 01:48
    关注

    All good here. What version of jQuery are you using ?

    I'll post my code :

    File jq.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
        <script>
    
        $(function(){
            var name = 'Telmo Dias';
    
            $.ajax({
                type:'POST',
                url:'pageAjax2.php',
                data:'name='+name,
                success: function(data){
                    $('#content').html(data);
                }
            });
        });
        </script>
    </head>
    <body>
        <div id="content"></div>
    </body>
    </html>
    

    File pageAjax2.php :

    <?php echo "Hello ".$_POST['name'];?>
    

    Result:

    Result

    评论

报告相同问题?

悬赏问题

  • ¥15 请提供一个符合要求的网页链接。
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码