Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry, but my all attempts to reproduce your problems were without success. In other words all POSTs were <em>with</em> HTTP body and the Ajax requests worked correctly. So I could not reproduce the problem which you described. I made all tests on Internet Explorer 10, Windows 8 W64 RTM Enterprise with all current windows updates.</p> <p>If I add some item (for example the first one) to the chat on <a href="https://www.steps.org.au/Shop/Health-Products/" rel="nofollow">the page</a> you referenced I can see that POST request the the following header will be produced:</p> <pre class="lang-none prettyprint-override"><code>Anforderung POST /~do HTTP/1.1 Accept */* Content-Type application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With XMLHttpRequest Referer https://www.steps.org.au/ Accept-Language de-DE,de;q=0.8,ru;q=0.7,en-US;q=0.5,en;q=0.3,ja;q=0.2 Accept-Encoding gzip, deflate User-Agent Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch) Host www.steps.org.au Content-Length 81 DNT 1 Connection Keep-Alive Cache-Control no-cache Cookie __utmc=91949528; __utma=91949528.365135675.1353268932.1353268932.1353268932.1; __utmb=91949528.1.10.1353268932; __utmz=91949528.1353268932.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=ka4shsgkfvnvfdcath2klh9un0; cartID=4a90a72a379989f597276ca30c79c6f6 </code></pre> <p>One can see that <code>Content-Length</code> is 81 and it's not 0. The body is</p> <pre><code>i=1211&amp;q=1&amp;token=00f5e9f5768d09ae67f2016ebcb62e99a0d75345&amp;cmd=addToCart&amp;sideBar=1 </code></pre> <p>The request will be answered with HTML fragment and the button become green.</p> <p>To be exactly during adding the item to the chat it will be executed <em>another code as you posted in your question</em>. It will be executed the following code (lines 49-74) from <a href="https://www.steps.org.au/js/shop.1352417874.js" rel="nofollow">shop.1352417874.js</a>:</p> <pre class="lang-js prettyprint-override"><code>var n; function inCart(i,t){ var a = $('#add'+i); var q = t?1:$('#qty'+i).val(); setLoader(a,(t?60:0),0); if(!t) a.addClass('loading').html('').attr('href','javascript:;'); // d = 'i='+i+'&amp;q='+q+'&amp;token='+TOKEN+'&amp;cmd=addToCart&amp;sideBar=1'; $.ajax({ data: { i:i, q:q, token:TOKEN, cmd:"addToCart", sideBar: 1 }, success: function(h){ $('#sideCartContents').replaceWith(h); mkButtons(); jsEnhance(); setLoader(); n=0; if(!t) a.removeClass('loading').addClass('green').attr('href','Shop/Checkout.html').html('Checkout').parent().find('div.QTY').html('&lt;strong&gt;x'+q+'&lt;/strong&gt; &lt;span class="inC"&gt;in cart&lt;/span&gt;'); flashCart(); } }); } </code></pre> <p>The values of local <code>i</code> and <code>q</code> variables was <code>1211</code> and <code>1</code> in my test.</p> <p>So I could not see any errors which you describe. So you have to debug the code <em>in your environment where it will be reproduced</em>. During the tests I would recommend you to use non-minimized code of jQuery. You could debug the code of jQuery.ajax to localize your problem.</p> <p>Nevertheless I have some additional advice to you:</p> <ol> <li>First of all you should include <code>error</code> callback to the <code>$.ajax</code> call and not only <code>success</code> callback.</li> <li>You should review the JavaScript code which you use. In the above code fragment for example you defined <strong>global</strong> variable <code>n</code> which will be property of the global <code>window</code> object. Introduction of such variables is very dangerous because of side effects and conflicts with other JavaScript codes which you include on the page. In some other places you set new properties of <em>global</em> <code>window</code> object indirectly. For example the code of <em>global</em> <code>doErrors</code> function defined in <a href="https://www.steps.org.au/js/common.1345011838.js" rel="nofollow">common.1345011838.js</a> looks as following</li> </ol> <pre class="lang-js prettyprint-override"><code>function doErrors(e,d){ e=e.split(','); for(i in e){ $((d?d+' ':'')+'[name="'+e[i]+'"]:visible').addClass('error'); } errors(); } </code></pre> <p>In the above code you use <code>i</code> variable without define it. So you set (or use) <code>window.i</code> variable in the way. It's clear the usage of <code>for-in</code> loop in case of array is not good. One could rewrite the code with equivalent code like <code>for(var i=0,l=e.length; i&lt;l; i++) {...}</code>.</p> <p>Moreover you start the code of <code>common.1345011838.js</code> with</p> <pre><code>var w,r,i,p,t,l,c,z,e,m,b,k,u,s,CPH,TOKEN; var z = new Array(); var ROOT; </code></pre> <p>which define many <strong>global</strong> variables with short names. It's very bad style. It can follow to conflicts with other modules which you included. Typically it would be enough to define <em>the most</em> variables which you need inside of some function. You could move declaration of the most variables inside of <code>$(document).ready(function(){/*.HERE.*/});</code>.</p> <p>If you really need to define some <em>global</em> variables you could define <em>one</em> which will be like the namespace and all other variables you could define as the <em>properties</em> of the only global object. It's the standard practice. In the way one can reduce the number of possible conflicts between different modules which you use. For example you could use something like</p> <pre><code>MYGLOBALCHATOBJECT = { root: "/", z: [], }; ... // add new property MYGLOBALCHATOBJECT.TOKEN = "some value"; </code></pre> <p>You should confider to define many function inside of context of another functions. In the way you could reduce the need to define many global variables. Just an example The above code of <code>inCart</code> use <code>n</code> variable defined above of <code>inCart</code> function. The variable <code>n</code> will be used <strong>only inside of</strong> other global function <code>flashCart</code> defined directly after <code>inCart</code>. Moreover the function <code>flashCart</code> will be used only inside of callback <code>success</code>. So you can rewrite the code so, that you define both <code>n</code> and <code>flashCart</code> inside of callback <code>success</code>:</p> <pre><code>... success: function (h) { // define LOCAL variable n var n = 0; // define LOCAL function which can use outer variable n function flashCart(){ if(n&lt;3) { setTimeout("flashCart()",120); n=n+1; } $('#sideCartBox').toggleClass('highlighted'); } $('#sideCartContents').replaceWith(h); mkButtons(); jsEnhance(); setLoader(); if(!t) a.removeClass('loading').addClass('green').attr('href','Shop/Checkout.html').html('Checkout').parent().find('div.QTY').html('&lt;strong&gt;x'+q+'&lt;/strong&gt; &lt;span class="inC"&gt;in cart&lt;/span&gt;'); flashCart(); // we use LOCAL function } </code></pre> <p>I would recommend you additionally to test your code in <a href="http://www.jshint.com/" rel="nofollow">JSHint</a> or <a href="http://www.jslint.com/" rel="nofollow">JSLint</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload