【发布时间】:2015-02-23 16:26:15
【问题描述】:
编辑:
这是 localhost 的问题,我认为是 htaccess 文件。尽管我无法在 localhost 中运行,但该脚本在 Web 主机上运行良好。
我想在 codeigniter 中使用 ajax 将表单数据存储到数据库中。问题是一切都很好,除了我收到 500 服务器内部错误。
我的控制器:
public function order()
{
$order = $this->main_model->order($_POST);
if($order)
{
return true;
}
else
{
return false;
}
}
我的模特:
function order($options = array())
{
$options = array(
'client_Name' => $this->input->post('oName'),
'client_Phone' => $this->input->post('oPhone')
);
$this->db->insert('md_orders', $options);
return $this->db->insert_id();
}
当然我正在使用 stepsForm 脚本,这是我拥有的 js 代码:
var theForm = document.getElementById( 'theForm' );
new stepsForm( theForm, {
onSubmit : function( form ) {
var form_data = {
oName: $('#oName').val(),
oPhone: $('#oPhone').val(),
};
$.ajax({
url: "<?php echo base_url() . 'main/order/'; ?>",
type: 'POST',
data: form_data,
success: function(msg) {
alert(msg);
}
});
}
} );
这是 HTML 代码:
<form id="theForm" class="simform" autocomplete="off">
<ol class="questions" id="questions">
<li>
<span><label for="oName">Your name:</label></span>
<input class="finput" id="oName" name="oName" type="text"/>
</li>
<li>
<span><label for="oPhone">Your Phone Number:</label></span>
<input class="finput ltr" data-validate="number" id="oPhone" name="oPhone" type="text"/>
</li>
</ol>
</form>
我得到的错误是:
POST http://localhost/123/main/order/ 500 (Internal Server Error)
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
并且没有任何内容存储在数据库中。我做错了什么?!
【问题讨论】:
-
您的 js 代码是在单独的 .js 文件中还是在您的视图中?
-
它在视图内
标签: php jquery mysql ajax codeigniter