Prototype js Ajax evalJSON()

Reply

Join Date: Apr 2009
Posts: 1
Reputation: twistedind is an unknown quantity at this point 
Solved Threads: 0
twistedind twistedind is offline Offline
Newbie Poster

Prototype js Ajax evalJSON()

 
0
  #1
Apr 7th, 2009
Below is my javascript code. It seems to hanging up at the "var data = transport.responseText.evalJSON();" part.

Here is a link to see how my html is made.
http://twisted.visionsminis.com/price/compressors

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. if (!window.WAUpdater) var WAUpdater = new Object();
  2.  
  3. WAUpdater.Methods =
  4. {
  5. options: {
  6. redirectOnError: true,
  7. baseUrl: "",
  8. updateColor:'#666666',
  9. mode:"add",
  10. removeRow:null
  11. },
  12. _options: new Object,
  13. setOptions: function(options) {
  14. Object.extend(this.options, options || {});
  15. },
  16.  
  17. showAjaxModal: function()
  18. {
  19. Modalbox.show('<div id="MB_loading"><br/>Please wait...</div>');
  20. },
  21.  
  22. updateMiniCart: function(transport, options)
  23. {
  24. this.setOptions(options);
  25. Modalbox.hide();
  26. window.scroll(0,0);
  27. var data = transport.responseText.evalJSON();
  28. //IF THERE'S ANY ERROR
  29. if(data.error)
  30. {
  31.  
  32. if(this.options.redirectOnError)
  33. {
  34. if(data.url) window.location = data.url;
  35. else history.go(-1);
  36. }
  37. else
  38. {
  39. var error_msg = 'Sorry. There was an error in your operation.';
  40. if(data.error_msg) error_msg = data.error_msg;
  41. Modalbox.show('<div id="MB_message">ERROR:'+error_msg+'</div>',{modal:true});
  42. }
  43.  
  44. }
  45. else
  46. {
  47. var item_count= data.item_count;
  48. var cart_subtotal = data.cart_subtotal;
  49. var onepage_checkout = data.onepage_checkout;
  50. var link_text = data.link_text;
  51. var cart_subtotal_str = data.cart_subtotal_str;
  52. var cart_subtotal_tax = data.cart_subtotal_tax;
  53. var my_cart_str = data.my_cart_str;
  54. var qty_str = data.qty_str;
  55. var checkout_str = data.checkout_str;
  56. var no_cart_str = data.no_cart_str;
  57.  
  58. //update item count on top menu
  59. if($$('a.top-link-cart').size()!=0 && link_text)
  60. {
  61. $$('a.top-link-cart')[0].update(link_text);
  62. }
  63.  
  64.  
  65. if(this.options.removeRow)
  66. {
  67. if($$('.mini-cart h5').size()!=0 && item_count==0)$$('.mini-cart h5')[0].remove();
  68. new Effect.SlideUp(this.options.removeRow);
  69. }
  70.  
  71. //update recently added items
  72. if(data.recent_items)
  73. {
  74. if($$('.mini-cart h5').size()!=0) $$('.mini-cart h5')[0].remove();
  75. if($$('.mini-cart .content').size()!=0) $$('.mini-cart .content')[0].remove();
  76. if($$('#cart-sidebar').size()!=0) $$('#cart-sidebar')[0].remove();
  77. // insert recently updated items after checkout button
  78. if ($$('.mini-cart').size() != 0) {
  79. $$('.mini-cart')[0].insert(data.recent_items);
  80. decorateList('cart-sidebar', 'non-recursive');
  81. new Effect.SlideDown('cart-sidebar');
  82. }
  83. }
  84.  
  85. //total price
  86. if($$('.mini-cart .head').size()!=0)
  87. {
  88. var minicart_itemcount = qty_str;
  89.  
  90. if(item_count > 0)
  91. {
  92. var minicart_string = '<h4>'+my_cart_str+'</h4>'+minicart_itemcount + '<p class="subtotal">'+cart_subtotal_str+'<strong>'+cart_subtotal+'</strong>'+cart_subtotal_tax +'</p>';
  93. if($$('.mini-cart .actions').size() ==0 && onepage_checkout)
  94. {
  95. $$('.mini-cart .head')[0].insert({
  96. after: '<div class="actions"><button class="form-button" onclick="setLocation('+this.options.baseUrl+'\'/index.php/checkout/onepage/\')" type="button"><span>'+checkout_str+'</span></button></div>'
  97. });
  98. }
  99. }
  100. else
  101. {
  102. if($$('.mini-cart .actions').size() !=0) $$('.mini-cart .actions')[0].remove();
  103. var minicart_string = '<h4>'+my_cart_str+'</h4>';
  104. $$('.mini-cart .head')[0].insert({
  105. after: '<div class="content"><p>'+no_cart_str+'</p></div>'
  106. });
  107. }
  108.  
  109. $$('.mini-cart .head')[0].update(minicart_string);
  110.  
  111. new Effect.Highlight($$('.mini-cart .head')[0],{startcolor: this.options.updateColor});
  112. if($$('.mini-cart .head .head').size()!=0) new Effect.Highlight($$('.mini-cart .head .head')[0],{startcolor: this.options.updateColor});
  113. if($$('.mini-cart .actions').size()!=0) new Effect.Highlight($$('.mini-cart .actions')[0],{startcolor: this.options.updateColor});
  114. }
  115.  
  116. if($$('#shopping-cart-totals-table tfoot').size()!=0)
  117. {
  118. $$('#shopping-cart-totals-table tfoot')[0].update(data.totals_footer);
  119. $$('#shopping-cart-totals-table tbody')[0].update(data.totals_top);
  120. new Effect.Highlight($$('#shopping-cart-totals-table tfoot')[0],{startcolor: this.options.updateColor});
  121. new Effect.Highlight($$('#shopping-cart-totals-table tbody')[0],{startcolor: this.options.updateColor});
  122. }
  123.  
  124. }
  125. }
  126. };
  127.  
  128. Object.extend(WAUpdater, WAUpdater.Methods);
  129. function submit_ajax_cart(url)
  130. {
  131. new Ajax.Request(url, {
  132. method: 'get',
  133. onLoad:WAUpdater.showAjaxModal(),
  134. onComplete: function(transport)
  135. {
  136. bu = url.substring(0,url.lastIndexOf("/checkout") ) ;
  137. WAUpdater.updateMiniCart(transport, {baseUrl:bu, mode:"ADD"});
  138. }
  139. });
  140. }
  141.  
  142. function submit_ajax_cart_p(url)
  143. {
  144. window.opener.submit_ajax_cart(url);
  145. }
  146.  
  147. /* from this section on is premium */
  148. function delete_ajax_cart(url,row)
  149. {
  150. new Ajax.Request(url, {
  151. method: 'get',
  152. onLoad:WAUpdater.showAjaxModal(),
  153. onComplete: function(transport)
  154. {
  155. bu = url.substring(0,url.lastIndexOf("/checkout") ) ;
  156. WAUpdater.updateMiniCart(transport, {baseUrl:bu, mode:"DELETE", removeRow:row, redirectOnError: false});
  157. }
  158. });
  159. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 55
Reputation: kvdd is an unknown quantity at this point 
Solved Threads: 2
kvdd kvdd is offline Offline
Junior Poster in Training

Re: Prototype js Ajax evalJSON()

 
0
  #2
Apr 8th, 2009
Seems like a debugging issue, have you tried a (JavaScript) debugger? With a debugger you can easily step through the code, and see which variables are filled with what values, and when they change.

See it as a slowmotion running your webpage, while you can inspect every value if it is correct.

I use Netbeans:
www.netbeans.org

But there are more:
Addon for Firefox: https://addons.mozilla.org/nl/firefox/addon/216
Also you may use Firebug: https://addons.mozilla.org/nl/firefox/addon/1843

I hope this helped.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 1766 | Replies: 1
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC