Php Laravel 5.7中ajax POST的最低工作示例
有人能在刀片模板中展示一个Laravel5.7PostAjax示例和一个完整的最小工作示例吗?我知道网络上有一些资源,但我错过了一个简明、直截了当的例子。你可以这样做, web.php blade.phpPhp Laravel 5.7中ajax POST的最低工作示例,php,laravel,laravel-5.7,Php,Laravel,Laravel 5.7,有人能在刀片模板中展示一个Laravel5.7PostAjax示例和一个完整的最小工作示例吗?我知道网络上有一些资源,但我错过了一个简明、直截了当的例子。你可以这样做, web.php blade.php $(document).on('click', '.delete-button', function (e) { e.preventDefault(); var orderId = 1 $.ajax({ type: 'p
$(document).on('click', '.delete-button', function (e) {
e.preventDefault();
var orderId = 1
$.ajax({
type: 'post',
url: '/admin/order/' + orderId,
data: {
'_token': $('input[name=_token]').val(),
'data_one': 'dataone',
},
success: function () {
toastr.success('Order Has Been Deleted Successfully.');
},
error: function(XMLHttpRequest) {
toastr.error('Something Went Wrong !');
}
});
});
你可以这样做, web.php blade.php
$(document).on('click', '.delete-button', function (e) {
e.preventDefault();
var orderId = 1
$.ajax({
type: 'post',
url: '/admin/order/' + orderId,
data: {
'_token': $('input[name=_token]').val(),
'data_one': 'dataone',
},
success: function () {
toastr.success('Order Has Been Deleted Successfully.');
},
error: function(XMLHttpRequest) {
toastr.error('Something Went Wrong !');
}
});
});
}))
嘿,这是一个工作代码,我希望这将为你工作
$.ajax({
url: 'http://some.working/url',
type: "POST",
data: $('#formContainer').serialize(),
success: function (response) {
console.log('Success', response);
},
error: function (response) {
console.log('Error', response);
}
});
The data can be produced in many ways for example
1. Using serialize() method as shown in the above example.
2. Using FormData():
for example
var data = new FormData($('#formContainer'));
In both of the above example, one thing compulsory is that your form
must contain csrf field. which can be provided using any of the
following methods:
<input type="hidden" name="_token" value="{{ csrf_token() }}" >
or
{{ csrf_field() }}
or even more simply by just using
@csrf
in some where in your form.
In case you are not using any form, you can create the data object by
yourself like this
var data = {
_token: '{{ csrf_token() }}',
data1: 'Value1',
data2: 'Value2',
data3: 'Value2'
}
}))
嘿,这是一个有效的代码,我希望这对您有用。$.ajax({
$.ajax({
url: 'http://some.working/url',
type: "POST",
data: $('#formContainer').serialize(),
success: function (response) {
console.log('Success', response);
},
error: function (response) {
console.log('Error', response);
}
});
The data can be produced in many ways for example
1. Using serialize() method as shown in the above example.
2. Using FormData():
for example
var data = new FormData($('#formContainer'));
In both of the above example, one thing compulsory is that your form
must contain csrf field. which can be provided using any of the
following methods:
<input type="hidden" name="_token" value="{{ csrf_token() }}" >
or
{{ csrf_field() }}
or even more simply by just using
@csrf
in some where in your form.
In case you are not using any form, you can create the data object by
yourself like this
var data = {
_token: '{{ csrf_token() }}',
data1: 'Value1',
data2: 'Value2',
data3: 'Value2'
}
网址:'http://some.working/url',
类型:“POST”,
数据:$('#formContainer')。序列化(),
成功:功能(响应){
console.log('Success',response);
},
错误:函数(响应){
console.log('错误',响应);
}
});
数据可以通过多种方式生成,例如
1.使用serialize()方法,如上面的示例所示。
2.使用FormData():
例如
var数据=新的FormData($(“#formContainer”);
在上面的两个例子中,有一件事是必须的,那就是你的表单
必须包含csrf字段。可使用以下任何一种方式提供:
以下方法:
或
{{csrf_field()}}
或者更简单地说,只需使用
@csrf
在你身体的某些地方。
如果不使用任何表单,可以通过以下方式创建数据对象:
你是这样的吗
风险值数据={
_令牌:{{csrf_token()}}},
数据1:'Value1',
数据2:‘值2’,
数据3:“值2”
}
$.ajax({
网址:'http://some.working/url',
类型:“POST”,
数据:$('#formContainer')。序列化(),
成功:功能(响应){
console.log('Success',response);
},
错误:函数(响应){
console.log('错误',响应);
}
});
数据可以通过多种方式生成,例如
1.使用serialize()方法,如上面的示例所示。
2.使用FormData():
例如
var数据=新的FormData($(“#formContainer”);
在上面的两个例子中,有一件事是必须的,那就是你的表单
必须包含csrf字段。可使用以下任何一种方式提供:
以下方法:
或
{{csrf_field()}}
或者更简单地说,只需使用
@csrf
在你身体的某些地方。
如果不使用任何表单,可以通过以下方式创建数据对象:
你是这样的吗
风险值数据={
_令牌:{{csrf_token()}}},
数据1:'Value1',
数据2:‘值2’,
数据3:“值2”
}
定义Web路由
Route::get('currencies/fiat/changeStatus','FiatCurrencyController@changeStatus')->name("currencies.fiat.chanageStatus");
单击并调用此函数单击onclick=“changeStatus(1,0)”
全部完成。定义Web路由
Route::get('currencies/fiat/changeStatus','FiatCurrencyController@changeStatus')->name("currencies.fiat.chanageStatus");
单击并调用此函数单击onclick=“changeStatus(1,0)”
全部完成。你是说laravel ajax示例?你是说laravel ajax示例?