Developer forum

Forum » Templates » Ajax call fails only in IE

Ajax call fails only in IE

Michael Nielsen
Reply
I have an ajax addtocart function where I call a hidden page and exstract the html for the cart.

Problem is that it only works in Firefox, In IE there are periodically errors. The error I get is this

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Dynamicweb.eCommerce.Frontend.Cart.CartCatch.CatchCart(Int32 pageId, PageView Pageview) +1051
   Dynamicweb.eCommerce.Frontend.EcomPageLoadNotificationSubscriber.OnNotify(String notification, Object[] args) +62
   Dynamicweb.Extensibility.NotificationManager.Notify(String notification, Object[] args) +1136
   Dynamicweb.Frontend.PageView.Load() +1744
   Dynamicweb.Admin.Load.Page_Load(Object sender, EventArgs e) +62
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Anyone has a take on this?

Replies

 
Kevin Steffer
Reply
Could you paste your javascript code on how you create the ajax calls?
 
Michael Nielsen
Reply
Hi Kevin

Sure, here it is...

var $j = jQuery.noConflict();
    
function AddToBasket(productid) {
  $j("#" + productid + " .productadded").hide()
  $j("#" + productid + " .ajaxload").show()
  quantity = $j("#" + productid +  " input.productQuantity").val()
   $j.ajax({
  url: '/default.aspx?id=29&productid=' + productid + '&quantity=' + quantity + '&cartcmd=add',
  cache: false,
  dataType: 'html',
  success: function(htmlData){
    $j.ajax({
      url: '/default.aspx?id=29',
      cache: false,
      dataType: 'html',
      success: function(html){
        $j("#" + productid + " .ajaxload").hide()
        $j("#" + productid + " .productadded").show()
        $j(".smallCart").html(html);
      },
      error: function(){
        
      }
    });
  },
  error: function(jqXHR,textStatus, errorThrown){

    //$j(".productlistInfo").html(jqXHR.responseText);
  }
   });
};


 
Kevin Steffer
Reply
This post has been marked as an answer
 Hi Michael,

IE 9 is somehow more critical to correct javascript syntax than the others you are missing some ; at line end and a correct URL written i JavaScript is not done like valied XHTML with the & as seperator but just the & char.

Here's a corrected version of you javascript which I testet and it works

var $j = jQuery.noConflict();
     
function AddToBasket(productid) {
  $j("#" + productid + " .productadded").hide();
  $j("#" + productid + " .ajaxload").show();
  quantity = $j("#" + productid +  " input.productQuantity").val();
   $j.ajax({
  url: '/default.aspx?id=29&productid=' + productid + '&quantity=' + quantity + '&cartcmd=add',
  cache: false,
  dataType: 'html',
  success: function(htmlData){
    $j.ajax({
      url: '/default.aspx?id=29',
      cache: false,
      dataType: 'html',
      success: function(html){
        $j("#" + productid + " .ajaxload").hide();
        $j("#" + productid + " .productadded").show();
        $j(".smallCart").html(html);
      },
      error: function(){
         
      }
    });
  },
  error: function(jqXHR,textStatus, errorThrown){
 
    //$j(".productlistInfo").html(jqXHR.responseText);
  }
   });
};

Votes for this answer: 0
 
Michael Nielsen
Reply
Hi Kevin

That did the trick, thanks...

 

You must be logged in to post in the forum