开发者

post data with ajax and jquery to other page

开发者 https://www.devze.com 2023-03-19 15:23 出处:网络
How do I sent data from one page to another with $.ajax and go to that other page? If I try the codes below I only get an error on the second page (watch-video.php).

How do I sent data from one page to another with $.ajax and go to that other page? If I try the codes below I only get an error on the second page (watch-video.php).

I use this code on the videos.php page

$.ajax({
            type: "POST",
            url: "watch-video.php",
            data: {video: "test"},

            success: function(msg)
            {
                                $(location).attr('href',"watch-video.php");

            }
        });

I use this code on the watch-video.php page

<?php
$name=$_POST['video'];
?>

<html>
<body>

<?php echo $name; ?>

</body>
</html>

This gives me the same error on the watch-video.php page. The error is about this line:

    <?php
$name=$_POST['video'];
?>

The error I get is this:

Notice: Undefined index: video in `C:\wam开发者_开发百科p\www\website\watch-video.php on line 26`

I want to submit something to another page, and go to that page but without a form. It has to be done when I click on a div:

 $("#gvidbalk").click(function(){

It is for something like youtube, if you click on a video image you will go to another page where you can watch that video.


$.ajax({
    type:'POST',
    url:'insert.php',
    data:'name='+name+'&pass='+pass,
    success: function(data){
        alert(data);
    }
});

If you this use method you can easy pass data. It is very simple and easy.


You could do:

$.ajax({
            type: "POST",
            url: "watch-video.php",
        data: {video: "test"},

        success: function(msg)
        {
                           window.location.href = "watch-video.php";

        }
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消