Javascript 在laravel中通过ajax传递文件
我正在尝试通过laravel中的ajax上传图像 我有这段ajax代码Javascript 在laravel中通过ajax传递文件,javascript,php,jquery,ajax,laravel,Javascript,Php,Jquery,Ajax,Laravel,我正在尝试通过laravel中的ajax上传图像 我有这段ajax代码 $("#stepbutton2").focus(function(){ var formData = new FormData($("#form1")); $.ajax({ url: '/nominations/upload/image', data: formData, proce
$("#stepbutton2").focus(function(){
var formData = new FormData($("#form1"));
$.ajax({
url: '/nominations/upload/image',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
alert(data.url);
},
error: function(err){
alert(err);
}
});
});
和php文件:
public function image(){
$file = Input::file('largeImage');
$ext = $file->getClientOriginalExtension();
$newName = md5(time()).".$ext";
$path= "uploads/{$this->getDate()}";
$file->move($path, $newName);
$imageUrl = $path.'/'.$newName;
return Response::json(["success"=>"true", "url"=>$imageUrl]);
}
#stepbutton2
是一种按钮类型,不提交。
我收到了警报[Object Object]
,但它应该是上传的URL。
标记类似于:
<form id='form1'>
<input type='file' id='largeImage' name='largeImage'>
<input type='button' id='stepbutton2'>
</form>
我哪里出错了?我需要使用此url填充同一表单中的另一个字段,并继续填充表单以执行下一步 废话,我接近了错误的问题,这是正确的一个我用他们的解决方案,直到找不到答案。这就是为什么我在这里再次问这个问题。所以你做了
var formData=new formData($(“#form1”)[0])代码>但它不起作用?不,它对我没有帮助。我不知道这意味着什么,所以我重新开始了这个问题。