weixin_33709609 2016-12-13 19:43 采纳率: 0%
浏览 18

Ajax发布并重定向?

I know this question has been asked in various forms, but I'm very new to ajax and php and I was hoping for some help. I have a JS function that takes a passed variable that I'd like to post to a new page and then go to that page. However I'm not sure how to post to the next page then go to the page and get the data.

For example: my function takes a course name, I'd like to post the name to the new page and then redirect to the new page and assign the data to a textbox. Here's what I've tried:

 function clickLogo(val){
            console.log(val);
            $.ajax({
                url: 'newPage.php',
                type: 'POST',
                data: 'courseTitle=' +val,
                success: function (response) {
                       location.href = "newPage.php";
                },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.log(textStatus, errorThrown);
                }

            }); 
        }

/NEW PAGE/

   <?php
         include ('config.php');
         @ob_start();
         session_start();

         if ($_SERVER['REQUEST_METHOD'] == 'POST'){    
            $courseTitle = $_POST['courseTitle'];
            echo $courseTitle+"!!!";
            echo "<script type = 'text/javascript'>document.getElementById('#headerDiv').innerHTML = ".$courseTitle."</script>";
        }else{
            echo "NO POST!!";
        }
    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何让企业微信机器人实现消息汇总整合
    • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
    • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
    • ¥15 TLE9879QXA40 电机驱动
    • ¥20 对于工程问题的非线性数学模型进行线性化
    • ¥15 Mirare PLUS 进行密钥认证?(详解)
    • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
    • ¥20 想用ollama做一个自己的AI数据库
    • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
    • ¥15 请问怎么才能复现这样的图呀