weixin_33749242 2016-11-07 11:58 采纳率: 0%
浏览 3

从ajax调用php

I'm trying someting very basic and it doesn't work : (Im getting the alert 'Test' and that's it :( )

<script name="text/javascript">
    function myFunction(part_id, product_id, type)
    {
        alert('test');
        $.ajax({
            type: 'post',
            url: '2.php',
            data: {lname: "www", name: "Natalie"},
            complete: function (txt) {
                alert("complete");
                alert(txt);
            }
        });
    }
</script>

on 2.php I have only one line (on the same directory):

    echo "test has been run";
  • 写回答

2条回答 默认 最新

  • weixin_33714884 2016-11-07 12:05
    关注

    use with success event.It will get php result.

    See the different between success() & complete()

    <script name="text/javascript">
        function myFunction(part_id, product_id, type)
        {
            alert('test');
            $.ajax({
                type: 'post',
                url: '2.php',
                data: {lname: "www", name: "Natalie"},
               complete: function (txt) {
                   //do something
                },
                success: function (result) {
                    alert("success");
                    alert(result);//test has been run
                }
            });
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器