【发布时间】:2017-08-21 23:46:44
【问题描述】:
我正在尝试从出现错误的数据库中检索邮政编码 - 传递给 Illuminate\Database\Grammar::parameterize() 的参数 1 必须是数组类型,给定字符串。我不确定我的查询位置是否正确。提前致谢。
$countiesList 数组看起来像 = ["Beaverhead", "Big Horn",......]
模型中的功能是:
public static function counties_zip($countiesList)
{
$zipCodes= Zip::select('ZIPCode')
->distinct()
->whereIn('CountyName', $countiesList)
->orderBy('ZIPCode', 'asc')
->get();
return $zipCodes;
}
在控制器中:
public function zipCodes(Request $request) {
$zipCodes = Zip::counties_zip($request->counties);
return json_encode($zipCodes);
}
还有我的 jS:
$(".submit").on("click", function(){
myList = [];
$('.select2 option:selected').each(function() {
myList.push($(this).val())
});
$countiesList=myList;
console.log($countiesList);
$.ajax({
type: "get",
url: http_host + '/leads/regions/counties/zipcodes?counties=' + $countiesList,
data: { counties: $countiesList},
dataType: "json",
success: function (data) {
var htmlText = '';
for ( var i=0;i<data.length;i++ ) {
htmlText += '<div class="div-conatiner">';
htmlText += '<input type="checkbox">' + data[i].ZipCode;
htmlText += '<div>';
}
$(".main-div").append(htmlText);
}
});
});
【问题讨论】:
标签: javascript jquery arrays json laravel-5.2