0
部分レンダリングを使用してページをレンダリングしたいとします。私はそれをやり遂げることができる方法をajaxを使ってやりたい。 私はajaxに新しいので、私はそれについてもっと知りません。yii2でajaxを使用してメインページに別のページをレンダリングする方法
これは、私はこれが
</tr>
部分レンダリングを使用してページをレンダリングしたいとします。私はそれをやり遂げることができる方法をajaxを使ってやりたい。 私はajaxに新しいので、私はそれについてもっと知りません。yii2でajaxを使用してメインページに別のページをレンダリングする方法
これは、私はこれが
</tr>
簡単な例でレンダリングされなければならない
<td><?= Html::input('text' , 'name' = '[DefVendors]["name"]'); ?></td>
<td><?= Html::input('text' , 'name' = '[DefVendors]["address"]'); ?></td>
<td><?= Html::input('text' , 'name' = '[DefVendors]["email"]'); ?></td>
<td><?= Html::input('text' , 'name' = '[DefVendors]["contact"]'); ?></td>
<td><?= Html::input('text' , 'name' = '[DefVendors]["bank_name"]'); ?></td>
<td><?= Html::input('text' , 'name' = '[DefVendors]["bank_accountno"]'); ?></td>
<td><?= Html::dropDwonList($modelVendors , 'company_id' , arrayHelper::map(defCompanies::find()->all() , 'id' ,'name' , ['prompt' => 'Select Company'])) ?></td>
、ここをレンダリングするページです。
コントローラ
class ExampleController extends Controller {
public function actionIndex()
{
return $this->ajaxResponse(true, $this->renderPartial('your_view',[]));
}
private function ajaxResponse($success = true, $content = '')
{
$response = [
'success' => $success,
'content' => $content
];
echo json_encode($response);
return $success;
}
}
はJavaScript
$.get('example/index', (html) => {
var response = JSON.parse(html);
$('#your-selector').html(response.content);
});