| | |
Prototype js Ajax evalJSON()
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 1
Reputation:
Solved Threads: 0
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
Here is a link to see how my html is made.
http://twisted.visionsminis.com/price/compressors
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
if (!window.WAUpdater) var WAUpdater = new Object(); WAUpdater.Methods = { options: { redirectOnError: true, baseUrl: "", updateColor:'#666666', mode:"add", removeRow:null }, _options: new Object, setOptions: function(options) { Object.extend(this.options, options || {}); }, showAjaxModal: function() { Modalbox.show('<div id="MB_loading"><br/>Please wait...</div>'); }, updateMiniCart: function(transport, options) { this.setOptions(options); Modalbox.hide(); window.scroll(0,0); var data = transport.responseText.evalJSON(); //IF THERE'S ANY ERROR if(data.error) { if(this.options.redirectOnError) { if(data.url) window.location = data.url; else history.go(-1); } else { var error_msg = 'Sorry. There was an error in your operation.'; if(data.error_msg) error_msg = data.error_msg; Modalbox.show('<div id="MB_message">ERROR:'+error_msg+'</div>',{modal:true}); } } else { var item_count= data.item_count; var cart_subtotal = data.cart_subtotal; var onepage_checkout = data.onepage_checkout; var link_text = data.link_text; var cart_subtotal_str = data.cart_subtotal_str; var cart_subtotal_tax = data.cart_subtotal_tax; var my_cart_str = data.my_cart_str; var qty_str = data.qty_str; var checkout_str = data.checkout_str; var no_cart_str = data.no_cart_str; //update item count on top menu if($$('a.top-link-cart').size()!=0 && link_text) { $$('a.top-link-cart')[0].update(link_text); } if(this.options.removeRow) { if($$('.mini-cart h5').size()!=0 && item_count==0)$$('.mini-cart h5')[0].remove(); new Effect.SlideUp(this.options.removeRow); } //update recently added items if(data.recent_items) { if($$('.mini-cart h5').size()!=0) $$('.mini-cart h5')[0].remove(); if($$('.mini-cart .content').size()!=0) $$('.mini-cart .content')[0].remove(); if($$('#cart-sidebar').size()!=0) $$('#cart-sidebar')[0].remove(); // insert recently updated items after checkout button if ($$('.mini-cart').size() != 0) { $$('.mini-cart')[0].insert(data.recent_items); decorateList('cart-sidebar', 'non-recursive'); new Effect.SlideDown('cart-sidebar'); } } //total price if($$('.mini-cart .head').size()!=0) { var minicart_itemcount = qty_str; if(item_count > 0) { var minicart_string = '<h4>'+my_cart_str+'</h4>'+minicart_itemcount + '<p class="subtotal">'+cart_subtotal_str+'<strong>'+cart_subtotal+'</strong>'+cart_subtotal_tax +'</p>'; if($$('.mini-cart .actions').size() ==0 && onepage_checkout) { $$('.mini-cart .head')[0].insert({ 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>' }); } } else { if($$('.mini-cart .actions').size() !=0) $$('.mini-cart .actions')[0].remove(); var minicart_string = '<h4>'+my_cart_str+'</h4>'; $$('.mini-cart .head')[0].insert({ after: '<div class="content"><p>'+no_cart_str+'</p></div>' }); } $$('.mini-cart .head')[0].update(minicart_string); new Effect.Highlight($$('.mini-cart .head')[0],{startcolor: this.options.updateColor}); if($$('.mini-cart .head .head').size()!=0) new Effect.Highlight($$('.mini-cart .head .head')[0],{startcolor: this.options.updateColor}); if($$('.mini-cart .actions').size()!=0) new Effect.Highlight($$('.mini-cart .actions')[0],{startcolor: this.options.updateColor}); } if($$('#shopping-cart-totals-table tfoot').size()!=0) { $$('#shopping-cart-totals-table tfoot')[0].update(data.totals_footer); $$('#shopping-cart-totals-table tbody')[0].update(data.totals_top); new Effect.Highlight($$('#shopping-cart-totals-table tfoot')[0],{startcolor: this.options.updateColor}); new Effect.Highlight($$('#shopping-cart-totals-table tbody')[0],{startcolor: this.options.updateColor}); } } } }; Object.extend(WAUpdater, WAUpdater.Methods); function submit_ajax_cart(url) { new Ajax.Request(url, { method: 'get', onLoad:WAUpdater.showAjaxModal(), onComplete: function(transport) { bu = url.substring(0,url.lastIndexOf("/checkout") ) ; WAUpdater.updateMiniCart(transport, {baseUrl:bu, mode:"ADD"}); } }); } function submit_ajax_cart_p(url) { window.opener.submit_ajax_cart(url); } /* from this section on is premium */ function delete_ajax_cart(url,row) { new Ajax.Request(url, { method: 'get', onLoad:WAUpdater.showAjaxModal(), onComplete: function(transport) { bu = url.substring(0,url.lastIndexOf("/checkout") ) ; WAUpdater.updateMiniCart(transport, {baseUrl:bu, mode:"DELETE", removeRow:row, redirectOnError: false}); } }); }
•
•
Join Date: Jun 2008
Posts: 55
Reputation:
Solved Threads: 2
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.
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.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Adding javascript to a URL?
- Next Thread: javascript mind twister
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug captchaformproblem checkbox close codes css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player position programming prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n





