【发布时间】:2020-09-15 12:12:28
【问题描述】:
我被 ajax 卡住了,我有第一个选择框,它列出了发件人的所有国家,我还有第二个选择框,它也列出了接收者的国家。我使用 ajax 来附加国家,但现在的问题是,第二个选择框没有被填充。
我通过我的 php 函数调用国家/地区
public function country()
{
return $this->countries->getCountries();
}
我的路线
Route::get('/country', [ 'as' => 'customer.country', 'uses' => 'IndexController@country' ]);
我现在的 ajax
$.ajax({
type: "get",
url: "/country",
success: function (res) {
if (res) {
$.each(res,function(key,value){
$("#country").append('<option value="'+value+'">'+value+'</option>');
});
}
}
});
我的选择框如下
对于发件人:
<div class="col col-md-6">
<div class="form-group">
<label class="required">Receiver Country</label>
<select id="country" class="form-control" required>
<option selected disabled>Select Country</option>
</select>
</div>
</div>
那么对于接收者:
<div class="col col-md-6">
<div class="form-group">
<label class="required">Receiver Country</label>
<select id="country" class="form-control" required>
<option selected disabled>Select Country</option>
</select>
</div>
</div>
现在只有发送者的选择框总是被填充,而接收者不会。请问如何使用 ajax 填充两个选择框?。
已更新...请检查
【问题讨论】:
-
请显示您调用 ajax 的位置
-
public function country() { return $this->countries->getCountries(); }我的路线` Route::get('/country', [ 'as' => 'customer.country', 'uses' => 'IndexController@country' ]);` -
接收者和发送者的 id 相同
<select id="country" -
你在哪里调用 country()?请更新问题而不是在 cmets 中发布代码..
-
WEBPAGE中的AJAX在哪里调用?不是服务器代码
标签: javascript jquery ajax