我有一个@include一些内容的页面,我想@include使用ajax请求的刀片视图文件。我该怎么办
基本上,视图文件将从服务器
获取项目**price.blade.php**
@foreach ($items as $item)
<div class="item-post">
<div class="priceofitem">{{ $item->price }} </div>
我想在我的标签部分
中加入@include('price.blade.php')<ul class="tabs">
<li><a href="#tab1">Prices </li>
<div id="tab1">@include('price.blade.php')</div>
我不想在加载时自动包含该视图文件,因为我不想加载该标签的内容,除非用户点击它,如果用户想要价格而不是用户点击该标签,并且将发送一个AJAX请求以包含该文件。
希望我明确表示,如果你不理解我,请告诉我。
手指交叉
答案 0 :(得分:8)
你想要像
这样的东西$(document).ready(function() {
$("#tab1").click(function() {
$.ajax({
type: 'POST',
url : "/yourrouteview",
success : function (data) {
$("#tab1").html(data);
}
});
});
});
您的控制器和路线必须配置/ yourrouteview才能获得正确的视图(即@include(&#39; price.blade.php&#39;)
答案 1 :(得分:3)
发出ajax请求并从控制器函数返回视图,如:
invoke Devise::Generators::SharedViewsGenerator
create app/views/devise/shared
create app/views/devise/shared/_links.html.erb
invoke form_for
create app/views/devise/confirmations
create app/views/devise/confirmations/new.html.erb
create app/views/devise/passwords
create app/views/devise/passwords/edit.html.erb
create app/views/devise/passwords/new.html.erb
create app/views/devise/registrations
create app/views/devise/registrations/edit.html.erb
create app/views/devise/registrations/new.html.erb
create app/views/devise/sessions
create app/views/devise/sessions/new.html.erb
create app/views/devise/unlocks
create app/views/devise/unlocks/new.html.erb
invoke erb
create app/views/devise/mailer
create app/views/devise/mailer/confirmation_instructions.html.erb
create app/views/devise/mailer/email_changed.html.erb
create app/views/devise/mailer/password_change.html.erb
create app/views/devise/mailer/reset_password_instructions.html.erb
create app/views/devise/mailer/unlock_instructions.html.erb
在ajax return view('your_view');
函数中,将其附加到您想要的位置:
success
流程如下:
success: function(response){
$('#Id').html(response);
}
控制器:
$('#tab').click(function(){
// ajax call here
...
success: function(response){
$('#Id').html(response);
}
});
答案 2 :(得分:0)
像这样在laravel中使用带有获取请求的刀片引擎进行具有ID的ajax调用!试试这个。
private DateTime Sdate {get => dateTimePickerAppointment.Value;}
case 6:
MessageBox.Show("Specific Date required ", appSearch.ToString("X"));
// define new SQL command cmdDB as new SQL Command (SELECT...........)
SqlCommand cmd6 = new SqlCommand("SELECT TOP(200)Date ,[TimeSlot],[FullName],[Availability] FROM [qryGPAppointmentsSchedule] WHERE Availability IS NULL and Date = '" + Sdate + "'", con);
try
{
//define a new SQL Data Adapter sda as a new SQL Data Adapter
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd6;// SQL Adapter selection = cmdDB
DataTable dtAvailable = new DataTable();// defined new data table
sda.Fill(dtAvailable);//SQL adapter is to fill dtAvailable
dataGridViewAppointmentsAvailable.DataSource = cmd6;
BindingSource aSource = new BindingSource();
aSource.DataSource = dtAvailable;
dataGridViewAppointmentsAvailable.DataSource = aSource;
//sda.Update(dtAvailable);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
break;
答案 3 :(得分:-1)
通过ajax请求,您可以从服务器获取编译视图,并将该值输出到某个父根,例如promise。然后调用。
在服务器端,您可以在路由中使用HTTP请求的简单处理程序:
Route::get('/', function () {
return view('price'); // here you can pass params for compiling blade template
});