[英]Ajax code is not appending to html select statment
I have two selects, one to select the group and the other to show sub-group categories. 我有两个选择,一个用于选择组,另一个用于显示子组类别。
<div class="frmDronpDown">
<div class="row">
<label>group:</label><br/>
<select name="country" id="country-list" onChange="getState(this.value);">
<?php while($x--)
{
echo "<option value='.$group_id[$x].'>$group_name[$x]</option>";} ?>
</select>
</div>
<div class="row">
<label>Services:</label><br/>
<select name="state" id="state-list" class="demoInputBox">
</select>
</div>
</div>
and the jQuery
function: 和
jQuery
函数:
function getState(val) {
$.ajax({
type: "POSt",
url: "http://abcd/Get_Service.php",
data:'gp_id='+val,
success: function(data){
$("#state-list").html(data);
}
});
}
The PHP
outputs: PHP
输出:
<option value='5'>V Cut</option><option value='11'>Hair Wash Girls</option>
<option value='12'>Lakme Hair Cut</option>
I have tried many things but I'm still not getting the correct output. 我已经尝试了很多事情,但是仍然无法获得正确的输出。
you cannot set html property on a select box instead of that give an id to your services div say 您不能在选择框上设置html属性,而不能给服务div输入ID
<div class="row" id="services">
<label>Services:</label><br/>
<select name="state" id="state-list" class="demoInputBox">
</select>
</div>
and then in your php page put following html code around your output code in php file 然后在您的php页面中,将以下html代码放在php文件中的输出代码周围
<label>Services:</label><br/>
<select name="state" id="state-list" class="demoInputBox">
// Your php page output
</select>
and then finally in your ajax code do following changes. 然后最后在您的ajax代码中进行以下更改。
function getState(val) {
$.ajax({
type: "POSt",
url: "http://abcd/Get_Service.php",
data:'gp_id='+val,
success: function(data){
$("#services").html(data);
}
});
}
Rohan said in his comment : 罗汉(Rohan)在评论中说:
" Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at Get_Service.php. (Reason: CORS header 'Access-Control-Allow-Origin' missing) ." “ 跨域请求被阻止:同一起源策略不允许读取Get_Service.php上的远程资源。(原因:缺少CORS标头'Access-Control-Allow-Origin') 。”
That because you try to make an Ajax Request different than the original domain: Host and/or Port are different 那是因为您尝试使Ajax请求不同于原始域:主机和/或端口不同
Try with this JavaScript function : 尝试使用此JavaScript函数:
function getState(val) {
$.ajax({
type : "POSt",
url : "http://abcd/Get_Service.php",
data : "gp_id=" + val,
dataType : "jsonp",
crossDomain: true,
success : function(data){
$("#state-list").html(data);
}
});
}
function getState(val) {
$.ajax({
type: "POSt",
url: "http://abcd/Get_Service.php",
data:'gp_id='+val,
success: function(data){
document.getElementById("state-list").innerHTML=data;
}
});
}
try to override innerHTML of id state-list 尝试覆盖id状态列表的innerHTML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.