Php 在返回响应之前调用函数::Laravel 4中的json给出;parse:json数据后意外的非空白字符;
我的控制器Php 在返回响应之前调用函数::Laravel 4中的json给出;parse:json数据后意外的非空白字符;,php,ajax,json,laravel-4,Php,Ajax,Json,Laravel 4,我的控制器 public function electricityBillAddToCart(){ $accountNumber = Input::get( 'accountNumber' ); $amount = Input::get( 'amount' ); $userId = Auth::user()->id; $type = TransactionTypes::ELECTRICITY; if(is_numeric($account
public function electricityBillAddToCart(){
$accountNumber = Input::get( 'accountNumber' );
$amount = Input::get( 'amount' );
$userId = Auth::user()->id;
$type = TransactionTypes::ELECTRICITY;
if(is_numeric($accountNumber)) {
CartHelper::addToCart($userId, $accountNumber, $amount, $type);
return Response::json("Okay");
}
return Response::json("Error");
}
使用以下ajax请求调用上述函数
$.ajax({
url: "/addToCart/electricityBill",
type: "POST",
dataType:"json",
data: {'accountNumber': reloadto, 'amount': amount},
success: function (re) {
console.log("Success");
},
error: function(re) {
console.log("Error");
}
前端的响应将是[]“OK”,控制台中将打印“Error”。如果我在发送响应之前调用的静态函数被注释掉,它将正常工作(它将返回“OK”,并打印“Success”)。我评论的代码是
CartHelper::addToCart($userId, $accountNumber, $amount, $type);
有人知道这是为什么吗?我发现了问题。CartHelper类中出现了回声。一旦删除,它就可以正常工作了