简体   繁体   中英

jquery ajax, not returning HTML

I have an ajax request that looks like this,

$("#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;
            });

This should make a request to a URL and pull back a HTML segment, the PHP code the ajax is calling, looks like this;

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);
}

However when I run the method, the HTML is not returned as I imagine it would be, and if I alert html in my javascript I get a black dialog box.

Any reason for this, have I done something wrong?

你有没有尝试过:

dataType: 'html'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM