【发布时间】:2020-09-06 18:42:40
【问题描述】:
我的代码中出现此问题的一部分得到以下逻辑:
view1 通过链接获取一些信息。当用户单击链接 X 时,会向 XAMPP Web 服务器上的控制器发送一个发布请求,以从链接 X 打开 view2。此外,所有这些都附加在 yii 框架中,而我是新来的。
HTML 视图1:
<a id="article-title1" type="button" onclick="myFunction()">
Js:
function myFunction()
{
alert('allo my function');
dataString = "hallo";
$.ajax({
type:"POST",
url:"http://localhost/basic/web/example/hello",
data:{'dataString':dataString},
success:function (data) {
console.log("send success");
}
});
}
控制器:
public function actionHello() {
$nom = "david";
$prenom = "pascal";
return $this->render('information',[
'name' => $nom,
'prenom' => $prenom
]);
}
php 视图2:
<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
$this->title = 'information';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class = "site-information">
<h1><?= Html::encode($this->title) ?></h1>
<p>
This is the information page
</p>
<p>
<b>name:</b><?= $name ?>
</p>
<p>
<b>firstname:</b><?= $firstname ?>
</p>
<code><?= __FILE__ ?></code>
</div>
此外,浏览器中的 ajax url(http://localhost/basic/web/example/hello) 工作正常。但是我不知道为什么view2的渲染在收到ajax请求后没有显示在浏览器中。
【问题讨论】: