我在laravel中做了一个ajax序列化,但是我已经咨询过并且注意到所有这种类型的ajax都调用了来自form :: open的路由,没有办法调用固定路线?是这样的:如何用ajax序列化调用控制器的路由
var formId = '#radicado';
var token = document.getElementById('token').value;
$.ajax({
async: true,
headers: {'X-CSRF-TOKEN': token},
url: ip+'/storeVersion',
type: 'POST',
data: $(formId).serialize(),
dataType: 'html',
success: function(result){
$(formId)[0].reset();
alert(result);
document.getElementById("version").style.display = "none";
document.getElementById("preview").style.display = "none";
parent.formulario.location.reload()
},
error: function(){
alert('No se ha actualizado el documento.');
}
});
和路线
Route::post('storeVersion','[email protected]');
为什么不能简单地插入* fixed * URL('url:'http:// example.com/path/to/method''),然后将该URL路由到您的控制器并处理来自那里的数据? – Marcus
此javascript是否被加载到刀片文件中?如果'/ storeVersion'出现在root之后,即'yourapp.com/storeVersion',则应该使用相对路径并将url设置为'/ storeVersion'。这样,它可以在任何域上运行。 – user3158900