Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在js中将数据从一个页面传递到另一个页面_Javascript_Php_Jquery_Angularjs - Fatal编程技术网

Javascript 如何在js中将数据从一个页面传递到另一个页面

Javascript 如何在js中将数据从一个页面传递到另一个页面,javascript,php,jquery,angularjs,Javascript,Php,Jquery,Angularjs,我使用angular js创建了一个新的博客项目。在这里,我有一个页面列出了所有的博客,如果我点击编辑按钮或删除按钮,我想移动到下一个页面,并在我更新博客的表单中显示数据 我的博客列表页面:listblog.html <!DOCTYPE html> <html lang="en"> <head> <title>My First AngularJs Blog</title> <script type="text/

我使用angular js创建了一个新的博客项目。在这里,我有一个页面列出了所有的博客,如果我点击编辑按钮或删除按钮,我想移动到下一个页面,并在我更新博客的表单中显示数据

我的博客列表页面:listblog.html

<!DOCTYPE html>
<html lang="en">

<head>



    <title>My First AngularJs Blog</title>

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/blog-home.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body ng-app="blogapp">

    <!-- Navigation -->
   <div ng-include="'includes/header.html'">                    
</div>

    <!-- Page Content -->



       <div class="container">
 <div ng-controller="blogcontroller">
  <h2>Blog List</h2>
  <p>Here is the awsome blog list</p>            
  <table class="table">
    <thead>
      <tr>
        <th>Title</th>
        <th>Blog</th>
        <th>Posted On</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <tr  ng-repeat="blg in allblog">
        <td>{{blg.title}}</td>
        <td>{{blg.description}}</td>
        <td>{{blg.created_on }}</td>
        <td><a href="">Edit</a> || <a href="">Delete</a></td>
      </tr>

    </tbody>
  </table>

  </div>
</div>


        <hr>

        <!-- Footer -->

 <div ng-include="'includes/footer.html'">                    
</div>

    <!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
<script src="controller.js"></script>
</body>

</html>

以及执行所有操作的php脚本页面 allscript.php

<?php 

$user ="root";
$pass ="m2n1shlko";

$dbh = new PDO('mysql:host=localhost;dbname=blog_db', $user, $pass);


switch($_GET['action']){

    case 'edit_post':
        edit_post();
    break;





function edit_post(){

  $data = json_decode(file_get_contents("php://input"));     
    $index = $data->id; 

$query = $dbh->prepare("SELECT * FROM blog_list where id='$index'") ;
$da = $query->execute();
$getre = $da->fetch(PDO::FETCH_ASSOC);

print_r(json_encode($getre));
return $getre;


}



}
?>

您可以使用在不同页面之间保存数据

$window.sessionStorage

实际上@Jeremy Thille是对的。。。有关更多信息,请查看路由模块。
此外,最佳做法是重构所有连接/发布/进入工厂/服务,并将它们直接注入控制器(需要的地方)


祝你好运。

使用Angular,你不应该把所有的东西都擦干净,然后完全改变页面。Angular有一个支持单页应用程序的应用程序,同时看起来你在另一个页面上。但实际上,内容是在同一页面中动态加载的,只有URL中的哈希值会发生变化。这样,您可以将所有数据和控制器保存在一个页面中。问题解决了。请浏览angular documentation网站上的教程。将向您展示路由基础是如何工作的。
<?php 

$user ="root";
$pass ="m2n1shlko";

$dbh = new PDO('mysql:host=localhost;dbname=blog_db', $user, $pass);


switch($_GET['action']){

    case 'edit_post':
        edit_post();
    break;





function edit_post(){

  $data = json_decode(file_get_contents("php://input"));     
    $index = $data->id; 

$query = $dbh->prepare("SELECT * FROM blog_list where id='$index'") ;
$da = $query->execute();
$getre = $da->fetch(PDO::FETCH_ASSOC);

print_r(json_encode($getre));
return $getre;


}



}
?>