Laravel 3 使用 Ajax 加载视图时出现问题
Laravel 3 issues with loading Views using Ajax
我有一个包含多个 <FORM>
s
的页面
例如:
@foreach($build['products'] as $productid)
<form id="productid_49" method="POST" action="/products/49/custom">
<input type="hidden" name="csrf_token" value="">
<input type="button" id="btn_49" value="Click">
</form>
<div id="form_output_49">
</div>
<form id="productid_23" method="POST" action="/products/23/custom">
<input type="hidden" name="csrf_token" value="">
<input type="button" id="btn_23" value="Click">
</form>
<div id="form_output_23">
</div>
<form id="productid_15" method="POST" action="/products/15/custom">
<input type="hidden" name="csrf_token" value="">
<input type="button" id="btn_15" value="Click">
</form>
<div id="form_output_15">
</div>
.
.
.
.
.
.
.
so on
@endforeach
当按钮被点击时,Jquery被调用:
$('input#btn_'+productid).click( function(e) {
e.preventDefault();
var form = $('#productid_'+productid);
var post_url = form.attr('action');
var post_data = form.serialize();
var div=$('#form_output_'+productid).html();
//console.log(post_url);
$.ajax({
type: 'POST',
url: post_url,
cache : false,
data: post_data,
success: function(data) {
$.post(post_url, function(data){
$('#form_output_'+productid).html(data);
});
}
});
});
路线:
Route::post('products/(:any)/custom', array('as' => 'compare', 'uses' => 'compares@custom'));
控制器:
public function post_custom($productid)
{
$compare = new Compare($product_id);
$compare->customsingelproduct($product_id);
}
库文件:
public function customsingelproduct($product_id)
{
$view = View::make('view.ajaxtest');
return $view;
}
它工作正常,但我似乎无法获得部分视图,因此我只能加载部分视图而不是重新加载整个页面。
有 render() 但它不起作用。
如何使用 AJAX 获取同一页面的部分视图并基本上执行 $('#form_output_'+productid).html(data);
或其他操作
希望我把问题描述清楚,如果不清楚请追问。
需要帮助
与 Laravel 3 一起工作。
使用 Jquery:
创建局部视图并正常加载
$('#form_output_'+productid).html(data);
我有一个包含多个 <FORM>
s
例如:
@foreach($build['products'] as $productid)
<form id="productid_49" method="POST" action="/products/49/custom">
<input type="hidden" name="csrf_token" value="">
<input type="button" id="btn_49" value="Click">
</form>
<div id="form_output_49">
</div>
<form id="productid_23" method="POST" action="/products/23/custom">
<input type="hidden" name="csrf_token" value="">
<input type="button" id="btn_23" value="Click">
</form>
<div id="form_output_23">
</div>
<form id="productid_15" method="POST" action="/products/15/custom">
<input type="hidden" name="csrf_token" value="">
<input type="button" id="btn_15" value="Click">
</form>
<div id="form_output_15">
</div>
.
.
.
.
.
.
.
so on
@endforeach
当按钮被点击时,Jquery被调用:
$('input#btn_'+productid).click( function(e) {
e.preventDefault();
var form = $('#productid_'+productid);
var post_url = form.attr('action');
var post_data = form.serialize();
var div=$('#form_output_'+productid).html();
//console.log(post_url);
$.ajax({
type: 'POST',
url: post_url,
cache : false,
data: post_data,
success: function(data) {
$.post(post_url, function(data){
$('#form_output_'+productid).html(data);
});
}
});
});
路线:
Route::post('products/(:any)/custom', array('as' => 'compare', 'uses' => 'compares@custom'));
控制器:
public function post_custom($productid)
{
$compare = new Compare($product_id);
$compare->customsingelproduct($product_id);
}
库文件:
public function customsingelproduct($product_id)
{
$view = View::make('view.ajaxtest');
return $view;
}
它工作正常,但我似乎无法获得部分视图,因此我只能加载部分视图而不是重新加载整个页面。
有 render() 但它不起作用。
如何使用 AJAX 获取同一页面的部分视图并基本上执行 $('#form_output_'+productid).html(data);
或其他操作
希望我把问题描述清楚,如果不清楚请追问。
需要帮助
与 Laravel 3 一起工作。
使用 Jquery:
创建局部视图并正常加载$('#form_output_'+productid).html(data);