这是我在Codeigniter项目中的视图文件。
<script type="text/javascript">
$(document).ready(function(){
// find the input fields and apply the time select to them.
$('#sample1 input').ptTimeSelect();
});
</script>
<script type="text/javascript">
function add_chamber() {
$.ajax({
url: "<? echo base_url("doctormain/add_chamber");?>",
type: "POST",
data: {
name : $("input#name").val()
address : $("input#address").val()
city : $("input#city").val()
locality : $("input#locality").val()
State: : $("input#state").val()
landline : $("input#landline").val()
mobile : $("input#mobile").val()
email : $("input#email").val()
days : $("input#mon").val()+$("input#tue").val()+$("input#wed").val()+$("input#thur").val()+$("input#fri").val()+$("input#sat").val()+$("input#sun").val()
start : $("input#start").val()
end : $("input#end").val()
comments : $("input#comments").val()
}
})
.success (function(response) { $('#sucess').html(response)})
.error (function() { alert("Error") ; });
}
</script>
<div class="content">
<div class="content-left">
<div class="row1">
<h2>Welcome <? echo $username ?></h2>
<h1> Add Chamber </h1>
<h2><div id="sucess"></div></h2>
<?php echo form_open_multipart('doctormain/add_chamber');?>
<table width="100%">
<tr><td> Name:</td><td> <input name="name" type="text" id="name"></td></tr>
<tr><td> Address:</td><td> <input name="address" type="text" id="address"></td></tr>
<tr><td> City:</td><td> <input name="city" type="text" id="city"></td></tr>
<tr><td> Locality:</td><td> <input name="locality" type="text" id="locality"></td></tr>
<tr><td> State:</td><td> <input name="state" type="text" id="state"></td></tr>
<tr><td> Landline:</td><td> <input name="landline" type="text" id="landline"></td></tr>
<tr><td> Mobile:</td><td> <input name="mobile" type="text" id="mobile"></td></tr>
<tr><td> Email:</td><td> <input name="email" type="text" id="email"></td></tr>
<tr>
<td> Days Of Availability:</td><td>
Mon:<input name="mon" type="checkbox" id="mon" value="1" checked>
Tue:<input name="tue" type="checkbox" id="tue" value="2" checked>
Wed:<input name="wed" type="checkbox" id="wed" value="3" checked>
Thur:<input name="thur" type="checkbox" id="thur" value="4" checked>
Fri:<input name="fri" type="checkbox" id="fri" value="5" checked>
Sat:<input name="sat" type="checkbox" id="sat" value="6" checked>
Sun:<input name="sun" type="checkbox" id="sun" value="7" checked>
</td></tr>
<tr><td> Time Of Availability</td><td>
<div id="sample1" class="ui-widget-content" style="padding: .5em;">
<p>
<label>Start</label>
<input name="s1Time2" id="start" value="" />
<label>End</label>
<input name="s1Time2" id="end" value="" />
</p>
</div>
</td></tr>
<tr><td> Comments:</td><td> <input name="comments" type="testbox" id="comments" ></td></tr>
<tr><td> </td><td> <input name="submit" id="submit" class="button" type="button" value="Save" onclick="add_chamber()">
</td></tr>
<? echo form_close();?>
</table>
<div id="results">
</div>
</div>
</div>
<div class="content-right">
<div class="mainmenu">
<h2 class="sidebar1">My Menu</h2>
<p><ul>
<li><a href="#">this is a dummy link 1</a></li>
<li><a href="#">this is a dummy link 2</a></li>
<li><a href="#">this is a dummy link 3</a></li>
<li><a href="#">this is a dummy link 4</a></li>
<li><a href="#">this is a dummy link 5</a></li>
<li><a href="#">this is a dummy link 6</a></li>
<li><a href="#">this is a dummy link 7</a></li>
<li><a href="#">this is a dummy link 8</a></li>
<li><a href="#">this is a dummy link 9</a></li>
<li><a href="#">this is a dummy link 10</a></li>
</ul></p>
</div>
</div>
</div>
但是,当我单击“保存”以执行所需的数据库输入工作时,我给了我一个错误
未捕获的ReferenceError:未定义add_chamber
我找不到问题出在哪里,任何人都可以就此错误帮助我。有什么关于范围或其他我不能指出的。
最佳答案
你的ajax电话全错了。
尝试
$.ajax({
url : url,
success : function(response){ },
error : function(){ }
});
function add_chamber()
{
$.ajax(
{
url: "<? echo base_url("doctormain/add_chamber");?>",
type: "POST",
data:
{
name : $("input#name").val(),
address : $("input#address").val(),
city : $("input#city").val(),
locality : $("input#locality").val(),
State: : $("input#state").val(),
landline : $("input#landline").val(),
mobile : $("input#mobile").val(),
email : $("input#email").val(),
days : $("input#mon").val()+$("input#tue").val()+$("input#wed").val()+$("input#thur").val()+$("input#fri").val()+$("input#sat").val()+$("input#sun").val(),
start : $("input#start").val(),
end : $("input#end").val(),
comments : $("input#comments").val()
},
success (function(response) { $('#sucess').html(response)}),
error (function() { alert("Error"); }
});
}