我希望我的位置顯示爲一個字符串。有人可以告訴我如何做到這一點?我只是新的laravel和JavaScript。 將JSON轉換爲字符串JAVASCRIPT
public function myformAjax(Request $request)
{
$position =Tbl_press_release_recipient::select('position')->where('country',Request::input('country'))->distinct()->get();
return json_encode($position);
}
我的ajax:
$(document).ready(function() {
$('#country').on('change', function() {
var country = this.value;
if(country){
$.ajax({
url: '/member/page/press_release_email/choose_recipient_press_release/ajax',
type: "GET",
data:{country:country},
dataType: "json",
success:function(data) {
$('select[name="position"]').empty();
$.each(data, function(key, value) {
$('select[name="position"]').append('<option value="'+ JSON.stringify(key) +'">'+ JSON.stringify(value) +'</option>');
});
}
});
}else{
alert("as23d");
}
});
});