我使用Opencart和MVC faramework。我需要通过AJAX提交表格。 Poblem是它插入BD,并进入成功,但在检查数据成功时它进入错误状态。找不到我的错误,也许我在控制器端出错。请帮我找到它,失去半天没有结果。
P.S。此外,如果我取消注释dataType:Json它停止完全工作,也不知道为什么。
这是HTML
<form class="form-horizontal" method="POST" id="form-callback">
<div class="cb" id="cb"></div>
<input type="hidden" name="product_id" id="product_id" value="{{ product_id }}" />
<div class="form-group">
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-8 pull-right">
<input type="text" class="form-control bluebord" name="name" id="namecb" placeholder="Ad" required />
</div>
</div>
<div class="form-group">
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-8 pull-right">
<input type="text" class="form-control bluebord" name="surname" id="surnamecb" placeholder="Soyad" required />
</div>
</div>
<div class="form-group">
<div class=" col-xs-12col-sm-12 col-md-10 col-lg-8 pull-right">
<input type="text" class="form-control bluebord" name="phone" id="phonecb" placeholder="+994(XX)XXX-XX-XX" required />
</div>
</div>
<div class="form-group">
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-8 pull-right">
<button type="button" id="submit_cb" data-action="{{ action_callback }}" data-loading-text="{{ text_loading }}" class="btn btn-porty btn-block">{{ button_order }}</button>
</div>
</div>
</form>
&#13;
这是AJAX
$(document).on('click', '#submit_cb', function(e) {
e.preventDefault();
var action = $(this).data('action');
var name = $('#namecb').val();
var surname = $('#surnamecb').val();
var phone = $('#phonecb').val();
var product_id = $('#product_id').val();
$.ajax({
type: "post",
url: action,
cache: false,
//dataType: "json",
data: {
'name': name,
'surname': surname,
'phone': phone,
'product_id': product_id
},
beforeSend: function() {
console.log('Start...');
},
success: function(data) {
if (data) { //NOT ENTERS TO THIS CONDITION
console.log(data);
} else {
console.log('error');
}
},
error: function() {
console.log('something went wrong');
}
});
});
&#13;
这是我的控制器
public function addCB(){
if($this->request->server['REQUEST_METHOD'] == 'POST'){
$this->load->model('callback/callback');
$this->model_callback_callback->addCall($this->request->post);
//$json['success'] = $this->language->get('text_success');
return $data['success'] = true;
}
}
&#13;