我想我在某个地方有一个简单的错误,但我看不到它!在我看来,我有以下 javascript 来创建表单:
$.ajax({
url:"<?php echo site_url('mycontroller/methodX/'.$ip.'/'.$hardwaremodel);?>",
type:'POST',
dataType:'json',
success: function(returnDataFromController) {
var htmlstring;
var submitFormHTML;
htmlstring = "<br><br><B>To reassign the port to a new vlan, click on a VlanId below and then click on the OK button</B><br><table class='table table-bordered table-striped'>";
htmlstring = htmlstring + "<th>VlanId</th><th>Name</th>";
for(i = 0; i < returnDataFromController.length; i++) {
}
submitFormHTML = "<form method='post' accept-charset='utf-8' action='/myapp/index.php/controllerABC/methodABC/"+ $('#ip').val() +"/" + $('#hardwaremodel').val() +"/" + $('#port').val() + "'><input type='text' id='newVlanID' style='width:5em;height:1.5em'/> <button type='submit' class='btn' id='saveVlan' style='width:10em;height:2em'>Reassign Vlan</button></form>";
//alert(submitFormHTML);
$('#clientajaxcontainer').html(htmlstring);
$('#newvlanform').html(submitFormHTML);
它是构建表单的“submitFormHTML”字符串。
在我的控制器中,我有以下逻辑来检查输入: public function methodABC() {
if($_POST){
echo 'I am here';
$form = $this->input->post();
var_dump($form);
exit();
}
else {
echo "false";
}
它总是打印“假”。我也尝试过使用:
print_r($this->input->post());
和
echo $this->input->post('newID');
但我似乎无法将数据从我的视图中获取到控制器中。你能看出我哪里错了吗?谢谢您的帮助。
编辑:
呈现页面时,会为表单创建以下 HTML:
<form method="post" action="/myapp/index.php/switches/changeportvlan/11.11.11.11 /">
<input type='text' id='newVlanID' style='width:5em;height:1.5em'/>
<button type="submit" class='btn' id='saveVlan' style='width:10em;height:2em'>Reassign Vlan</button>
</form>"