[英]jquery ajax, not returning HTML
我有一个看起来像这样的ajax请求,
$("#frmProducts").submit(function(){
var dataSet = $("#frmProducts").serialize();
$.ajax({
url: "<?php echo base_url();?>products/updateBasket",
data: dataSet,
type: "POST",
success: function(html){
$('html, body').animate({scrollTop:0}, 'slow');
$("#bagInfo").load("/checkout/loadCartView");
$('body').append(html);
$('#basketoverview').fadeIn(2000);
setTimeout(function () { $('#basketoverview').fadeOut(2000).hide(); }, 8000);
}
});
return false;
});
这应该向URL请求并拉回HTML段,即ajax调用的PHP代码,如下所示;
function updateBasket()
{
$this->load->model('Checkout_model');
$this->load->model('Product_model');
$derivativeId = $this->input->post('selDerivative-1');
$quantity = $this->input->post('selQuantity');
$derivative = $this->Product_model->GetProducts(array('pdId' => $derivativeId), 'small');
// Add item to shopping bag.
$attributes = $this->Product_model->GetProductDerivatives(array('pdId' => $derivativeId));
$this->Checkout_model->AddProduct($derivative, $attributes, $quantity);
$this->data['message'] = 'Item added to Shopping Bag.';
// Update Delivery Price
$this->Checkout_model->updateDelivery(49);
$this->data['items'] = $this->Checkout_model->GetProducts();
$this->template
->build('checkout/quickbasket', $this->data);
}
但是,当我运行该方法时,HTML不会像我想象的那样返回,并且如果我在javascript中警告html,则会出现一个黑色对话框。
出于任何原因,我做错了什么吗?
你有没有尝试过:
dataType: 'html'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.