简体   繁体   中英

JQuery ajax don't invoke remote page

I have this code :

<html>
    <head>
        <title>
            Test
        </title>
        <script type="text/javascript" src="jquery.js"></script>
        <?php
        session_start();
        ?>
    </head>
    <body>
        <?php
        if (isset($_REQUEST['modepayment']) && $_REQUEST['modepayment'] == 'success') {
            ?>



            <script>
                alert('alborz1');
                var user1 = "<?= $_SESSION['user'] ?>";
                var no_sms1 = "<?php echo $_SESSION['n_m']; ?>",
                var mail1 = "<?php echo $_SESSION['email']; ?>",
                var monto1 = "<?php echo $_SESSION['monto']; ?>",
                var refe1 = "<?php echo $_SESSION['refe']; ?>",
                var tipo_tar1 = "";
                var valueKeys = {tipo_tar:tipo_tar1, monto:monto1, n_m = no_sms1, refe:refe1, usuario:user1, email:mail1};
                $.ajax({type: "POST", url: "insertar.php", data: valueKeys,
                    success: function(data)
                    {
                        <?php
                        $_SESSION['n_m'] = '';
                        $_SESSION['email'] = '';
                        $_SESSION['monto'] = '';
                        $_SESSION['refe'] = '';
                        ?>
                        if (data.indexOf("SMS") >= 0) {
                            $(".centro").hide();
                            $(".content-area").hide();
                            $("#bodythxRecarga").show();
                        }
                    }
                });


            </script>




            <?php
        } else {
            ?>
            <script>alert('alborz');</script>
            <?php
        }
        ?>
        <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
    </body>

</html>

When I browse the page with payment.php?modepayment=success, only first alert is executed and ajax invoke didn't execute. I try all correction to ajax and array definition but nothing happen. inserar.php is exist and work properly but this ajax method didn't work. I use firebug and didn't see any ajax invokation.

You are only seeing one alert() and assuming your AJAX call is failing but in fact, it is succeeding. But by manually going to that page, you don't send any POST data for it to test against this:

if(data.indexOf("SMS")>=0){

and therefore you don't get the benefit of the rest of the code inside of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM