//控制器中的方法
public function actionAdd(){
$model = new need;
$arr = array(
'name' => $_POST['input-name'],
'nickname' => $_POST['input-nickname'],
'company' => $_POST['input-company'],
'email' => $_POST['input-email'],
'phone' => $_POST['input-mobile'],
'questions' => $_POST['input-question']
);
$model->attributes = $arr;
if($model->save()){
$response = array(
'errno'=>0,
'errmsg'=>'提交成功',
'data'=>true,
);
}else{
$response = array(
'errno'=>1,
'errmsg'=>'提交失败',
'data'=>false,
);
}
echo json_encode($response);
}
//js部分
function up(){
$.ajax({
type: "POST",
dataType: "json",
url: 'http://retax.xingyun.net/SchoolTraining/add',
data: $('form').serialize(),
success: function (response) {
if(response.errno==0){
alert('需求提交成功!');
}else{
alert('需求提交失败!请重新提交!')
};
},
});
}
//html form表单中的代码