我是Yii2的新用户我希望在点击优惠时显示左侧的优惠列表,它应显示右侧的详细信息。
这是我的tradesmanOffer查看页面
<?php
foreach ($model as $offer) {
?>
<div class="offer-row" data-id="<?=$offer->o_id?>">
<div class="box">
<div class="offer-col-7"> <div><b>NEW OFFER</b> from
<?php
if ($offer->c_id) {
$contractor = Contractor::getoffername($offer->c_id);
if (!empty($contractor)) {
echo $contractor->name;
}
}
?></div>
这是我的.js文件:
$(function () {
$(".offer-row").on("click", function (event) {
$(".offers").empty();
var tid = $(this).attr("data-id");
alert(1);
$.ajax({
url: "offer-details?t_id=" +tid,
type: "GET",
contentType: false,
cache: false,
success: function (data) {
//alert(2);
$("#ajaxdiv").html('');
$("#ajaxdiv").html(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
return false;
});
});
这是我的控制器页面,作为OfferController
public function actionOfferList() {
if (Yii::$app->session->get('t_id') != "") {
$model = new TradesmanOffer();
$t_id = Yii::$app->session->get('t_id');
$offers = $model->getOffers($t_id);
return $this->render('tradesmanOffer', ['model' => $offers]);
} else {
return $this->redirect('../site/index');
}
}
public function actionOfferDetails() {
$t_id= $_GET['t_id'];
$model = new TradesmanOffer();
$offer = $model->getOffers($t_id);
return $this->renderAjax('tradesmanOfferNew', ['model' => $offer]);
}
这是我的另一种观点tradesmanOfferNew:
<div> <b>NEW OFFER</b> from
<?php
if ($offer->c_id) {
$contractor = Contractor::getoffername($offer->c_id);
if (!empty($contractor)) {
echo $contractor->name;
}
}
?>
当我点击任何优惠并且刷新浏览器时,它应该在页面上显示相同的数据。 我怎么做到这一点?请帮助 提前谢谢
答案 0 :(得分:0)
为什么在你的ajax通话中使用contentType: false
?由于您从通话中获得了一些HTML,因此应将其设置为html