這是我的Ajax調用:返回一個函數的變量結果的Ajax響應
$("#cover-input").change(function(){
var file_data = $("#cover-input").prop("files")[0];
var form_data = new FormData();
form_data.append("cover_file", file_data);
//kaherdin
$.ajax({
url: 'update-cover',
type: 'POST',
dataType: 'script',
data: form_data,
contentType: false,
processData: false,
async: false,
success: function(resp){
console.log(resp);
},
error: function(err){
console.log('Likes error', err);
}
});
readURL_cover(this);
});
了我在basicly修剪和上載變更文件的功能。
public function updateCover(Request $request) {
$user = Sentinel::check();
$destinationPath = public_path('uploads/users');
if ($fileCover = $request->file('cover_file')) {
$input_cover = time().'.'.$fileCover->getClientOriginalExtension();
$img = Image::make($fileCover->getRealPath());
$img->fit(1920, 555, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input_cover);
// $user->cover = $input_cover;
$response = $input_cover;
return $response;
}
但是,這給我一個錯誤。我只想讓「input_cover」返回到我的ajax調用,以便我可以顯示更新後的圖片。 如果我將$ response = $ input_cover更改爲$ response = [$ input_cover];它工作糾結,但輸入是像:[「my_pic.jpg」]所以它不好。
什麼錯誤?你永遠不會在PHP腳本中調用該函數。 –
喜歡錯誤對象{readyState的:4,getResponseHeader:功能,getAllResponseHeaders:功能,setRequestHeader:功能,overrideMimeType:函數...} 呼叫在這裏做:$。阿賈克斯({ 網址: '更新蓋', – Kaherdin
_but這給我一個錯誤_你想與我們分享你得到什麼錯誤,或者我們應該做一些猜測嗎? – RiggsFolly