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>
    
    评论

报告相同问题?