values not updated after an ajax response

前端 未结 2 1734
遥遥无期
遥遥无期 2020-11-28 00:15

I am sending some form data via ajax to a php script in the same page. PHP must process the data and show results in the same page.

I am using this syntax for ajax:<

相关标签:
2条回答
  • 2020-11-28 00:35

    Pass the result as parameter to updatechart()

    $.ajax
    ({
        type: "POST",
        url: "",
        data: $("form").serialize(),
        success: function(result)
        {
            updatechart(result);      
        }
    }); 
    

    then access the results via parameter.

    function updatechart(result) {
    //.......
    //.......
    console.log(result);
    }
    

    Hope you're trying something like this.

    0 讨论(0)
  • 2020-11-28 00:36

    That is expected behavior. Move your PHP processing to a different page.

    $.ajax
    ({
        type: "POST",
        url: "anotherphppage.php",
        data: $("form").serialize(),
        success: function(result)
        {
            updatechart(result);      
        }
    }); 
    

    Try this and you'll see what I mean:

    <html>
        <head>
            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    
            <script type="text/javascript">
                $(document).ready(function() {
    
                    $('#mybutt').click(function() {
                        $.ajax({
                            type: "POST",
                            url: "",
                            data: 'myVar=Hello',
                            success: function(data) {
                                alert(data);
                            }
                        });
                    });
                }); //END $(document).ready()
    
            </script>
        </head>
    <body>
    
        Try this:<br />
        <input type="button" id="mybutt" value="Click Me">
    
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题