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 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿