Laravel 5.6 Ajax Post 500 内部服务器错误
Laravel 5.6 Ajax Post 500 Internal Server Error
你好,我正在通过 Ajax Post 请求发送大型字符串数据,它在本地主机上工作正常,但在实时服务器上不工作我正在发送一些图像数据,然后将此图像数据转换为图像在服务器上..发送此数据也需要很多时间平均数据大小在 4 到 7 MB 之间..您还可以建议一种更好的方法以便快速完成..还可以正确设置我包括 CSRF 令牌URL 也很好,但不知道为什么会出现此错误
错误 => 状态代码:500 内部服务器错误
我发送请求的控制器代码
$pid = $request->input('id');
$pt_id = $request->input('pt_id');
$pname = $request->input('name');
$isBack = $request->input('isBack');
$qty = $request->input('qty');
$paper = $request->input('paper');
$previewFront = $request->input('previewFront');
$previewBack = $request->input('previewBack');
$PrintDataFront = $request->input('PrintDataFront');
$PrintDataBack = $request->input('PrintDataBack');
$cart_item_id = uniqid();
//Store Img Data
$pf = str_replace('data:image/png;base64,', '', $previewFront);
$pf = str_replace(' ', '+', $pf);
$pf_n = $cart_item_id.'_f_.'.'png';
\File::put(public_path(). '/cart_preview/' . $pf_n, base64_decode($pf));
$pb = str_replace('data:image/png;base64,', '', $previewBack);
$pb = str_replace(' ', '+', $pb);
$pb_n = $cart_item_id.'_b_.'.'png';
\File::put(public_path(). '/cart_preview/' . $pb_n, base64_decode($pb));
$pdf = str_replace('data:image/png;base64,', '', $PrintDataFront);
$pdf = str_replace(' ', '+', $pdf);
$pdf_n = $cart_item_id.'_f_.'.'png';
\File::put(public_path(). '/orders/' . $pdf_n, base64_decode($pdf));
$pdb = str_replace('data:image/png;base64,', '', $PrintDataBack);
$pdb = str_replace(' ', '+', $pdb);
$pdb_n = $cart_item_id.'_b_.'.'png';
\File::put(public_path(). '/orders/' . $pdb_n, base64_decode($pdb));
//Get Prices and qty
$opriceitem = PriceTableItem::find($qty);
$itemQty = $opriceitem->qty;
$basePrice = $opriceitem->total;
if($isBack == 'true') {
$backPrice = $opriceitem->total_back;
$itemPrice = $opriceitem->total + $opriceitem->total_back;
$pricePerPiece = $opriceitem->item_price + $opriceitem->item_price_back;
}else {
$backPrice = 'INCLUDED';
$itemPrice = $opriceitem->total;
$pricePerPiece = $opriceitem->item_price;
}
if($paper == 'Premium White') {
$paperPrice = ($itemPrice/100) *60;
$itemPrice = $itemPrice + ($itemPrice/100) *60;
} else {
$paperPrice = 'INCLUDED';
}
//Get all Available Qty
$allQty = PriceTableItem::where('tid', $pt_id)->get();
$allAvailableQty = array();
foreach($allQty as $allqtyarry) {array_push($allAvailableQty, $allqtyarry->qty);}
//Create Cart Object
$item = [
"id" => $cart_item_id,
"pid" => $pid,
"name" => $pname,
"qty" => $itemQty,
"price_table_id" => $pt_id,
"paperType" => $paper,
"backCharges" => $backPrice,
"paperCharges" => $paperPrice,
"isBack" => $isBack,
"pricePerPiece" => $pricePerPiece,
"basePrice" => $basePrice,
"totalPrice" => $itemPrice,
"allQty" => $allAvailableQty,
];
$request->session()->put('cart.items.' . $cart_item_id, $item);
return 'Success';
Blockquote
Are you getting only error 500 and nothing else? If so, enable debug so you can get better description of the error. Make sure your php.ini file is set up properly and also permissions are fine for your server folders (I always get problems with the storage folder).
你好,我正在通过 Ajax Post 请求发送大型字符串数据,它在本地主机上工作正常,但在实时服务器上不工作我正在发送一些图像数据,然后将此图像数据转换为图像在服务器上..发送此数据也需要很多时间平均数据大小在 4 到 7 MB 之间..您还可以建议一种更好的方法以便快速完成..还可以正确设置我包括 CSRF 令牌URL 也很好,但不知道为什么会出现此错误
错误 => 状态代码:500 内部服务器错误
我发送请求的控制器代码
$pid = $request->input('id');
$pt_id = $request->input('pt_id');
$pname = $request->input('name');
$isBack = $request->input('isBack');
$qty = $request->input('qty');
$paper = $request->input('paper');
$previewFront = $request->input('previewFront');
$previewBack = $request->input('previewBack');
$PrintDataFront = $request->input('PrintDataFront');
$PrintDataBack = $request->input('PrintDataBack');
$cart_item_id = uniqid();
//Store Img Data
$pf = str_replace('data:image/png;base64,', '', $previewFront);
$pf = str_replace(' ', '+', $pf);
$pf_n = $cart_item_id.'_f_.'.'png';
\File::put(public_path(). '/cart_preview/' . $pf_n, base64_decode($pf));
$pb = str_replace('data:image/png;base64,', '', $previewBack);
$pb = str_replace(' ', '+', $pb);
$pb_n = $cart_item_id.'_b_.'.'png';
\File::put(public_path(). '/cart_preview/' . $pb_n, base64_decode($pb));
$pdf = str_replace('data:image/png;base64,', '', $PrintDataFront);
$pdf = str_replace(' ', '+', $pdf);
$pdf_n = $cart_item_id.'_f_.'.'png';
\File::put(public_path(). '/orders/' . $pdf_n, base64_decode($pdf));
$pdb = str_replace('data:image/png;base64,', '', $PrintDataBack);
$pdb = str_replace(' ', '+', $pdb);
$pdb_n = $cart_item_id.'_b_.'.'png';
\File::put(public_path(). '/orders/' . $pdb_n, base64_decode($pdb));
//Get Prices and qty
$opriceitem = PriceTableItem::find($qty);
$itemQty = $opriceitem->qty;
$basePrice = $opriceitem->total;
if($isBack == 'true') {
$backPrice = $opriceitem->total_back;
$itemPrice = $opriceitem->total + $opriceitem->total_back;
$pricePerPiece = $opriceitem->item_price + $opriceitem->item_price_back;
}else {
$backPrice = 'INCLUDED';
$itemPrice = $opriceitem->total;
$pricePerPiece = $opriceitem->item_price;
}
if($paper == 'Premium White') {
$paperPrice = ($itemPrice/100) *60;
$itemPrice = $itemPrice + ($itemPrice/100) *60;
} else {
$paperPrice = 'INCLUDED';
}
//Get all Available Qty
$allQty = PriceTableItem::where('tid', $pt_id)->get();
$allAvailableQty = array();
foreach($allQty as $allqtyarry) {array_push($allAvailableQty, $allqtyarry->qty);}
//Create Cart Object
$item = [
"id" => $cart_item_id,
"pid" => $pid,
"name" => $pname,
"qty" => $itemQty,
"price_table_id" => $pt_id,
"paperType" => $paper,
"backCharges" => $backPrice,
"paperCharges" => $paperPrice,
"isBack" => $isBack,
"pricePerPiece" => $pricePerPiece,
"basePrice" => $basePrice,
"totalPrice" => $itemPrice,
"allQty" => $allAvailableQty,
];
$request->session()->put('cart.items.' . $cart_item_id, $item);
return 'Success';
Blockquote Are you getting only error 500 and nothing else? If so, enable debug so you can get better description of the error. Make sure your php.ini file is set up properly and also permissions are fine for your server folders (I always get problems with the storage folder).