admin管理员组文章数量:1435859
I am new to code igniter and I have searched the following question in number of StackOverflow threads but none of them seem to solve my problem.
I have the following view code:
<select name="select1" id="select1">
<option value="0">None</option>
<option value="1">First</option>
</select>
<scriptsrc=".11.1/jquery.min.js"></script>
<script type="text/javascript">
// Ajax post
$(document).ready(function() {
$("#select1").change(function(event) {
event.preventDefault();
var id = $(this).val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/mycontroller/method",
dataType: 'json',
data: {id: id},
success: function(res) {
}
});
});
});
</script>
Ok when I change the drop down list selection nothing happens, which should actually call my controller method. Can you please help me resolve this problem?
Thanks
I am new to code igniter and I have searched the following question in number of StackOverflow threads but none of them seem to solve my problem.
I have the following view code:
<select name="select1" id="select1">
<option value="0">None</option>
<option value="1">First</option>
</select>
<scriptsrc="http://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
// Ajax post
$(document).ready(function() {
$("#select1").change(function(event) {
event.preventDefault();
var id = $(this).val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/mycontroller/method",
dataType: 'json',
data: {id: id},
success: function(res) {
}
});
});
});
</script>
Ok when I change the drop down list selection nothing happens, which should actually call my controller method. Can you please help me resolve this problem?
Thanks
Share Improve this question edited Jul 28, 2016 at 6:19 Hardik Vaghani 2,17327 silver badges47 bronze badges asked Jul 28, 2016 at 6:06 NaNNaN 1,0723 gold badges13 silver badges27 bronze badges 1- See browser console if any error is showing – Vinie Commented Jul 28, 2016 at 6:30
4 Answers
Reset to default 5You are using <select>
id as category
But In jquery you are calling $("#select1").change(function(event)
like this .
You just need to change $("#select1").change(function(event)
to
$("#category").change(function(event)
Check in console if your script contains any errors.
if no errors with script, check your function getting called after change, by adding alert or console statement.
if function getting called, check base_url. As per latest ment '/' missing.
You can also try Following snippet :
//Add J Query Library here
<select name="select1" id="select1" onchange="funName(this);">
<option value="0">None</option>
<option value="1">First</option>
</select>
<script type="text/javascript">
function funName(element)
{
var id = element.value;
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "/index.php/mycontroller/method",
dataType: 'json',
data: {"id" : id},
success: function(res) {
console.log(res);
}
});
}
</script>
There is mistake with your jquery selector.
you are using $("#select1").change(function(){});
you don't have any id reffered in this name in your section.
$("#category").change(function(event) {
//ur code here
});
You used id selector in the jquery code but that id is mentioned as a name attribute in html dropdown tag. So try the following code.
Change this following:-
<select name="select1" id="category">
<option value="0">None</option>
<option value="1">First</option>
</select>
<scriptsrc="http://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
// Ajax post
$(document).ready(function() {
$("#category").change(function(event) {
event.preventDefault();
var id = $(this).val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/mycontroller/method",
dataType: 'json',
data: {id: id},
success: function(res) {
}
});
});
});
本文标签: javascriptJQuery on dropdown list change is not working in codeigniterStack Overflow
版权声明:本文标题:javascript - JQuery on dropdown list change is not working in codeigniter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744509795a2609809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论