1

Apologies for the lack of knowledge to start with...

We have a page on our website that displays a price depending on the users selection of size width and quantity Unfortunately the dynamic calculator isn't showing the price, even though the script seems to be calculating the price...

Can anyone help me where I am going wrong :-(

When I debug in the console it displays the information correctly but just doesn't show!!!

EDIT:The javascript that should output the price is

    <script>
$(function() {
    $('#inputqty').keyup(function() {
        var inputqty = $('#inputqty').val();
        var sku = $('#selSKU').val();
        $.getJSON('pricecheck.cfc?method=getPrice&returntype=JSON&sku='+sku+'&qty='+inputqty, function(data) {
            $("#divPrice").html(data.displayPrice);
        });
    });

});

    function qtyChanged(){
        var inputqty = $('#inputqty').val();
        var sku = $('#selSKU').val();
        $.getJSON('pricecheck.cfc?method=getPrice&returntype=JSON&sku='+sku+'&qty='+inputqty, function(data) {
            $("#divPrice").html(data.displayPrice);
        });


    };
</script>
matthew
  • 377
  • 3
  • 5
  • 16
  • 1
    Please post up the snippets of js that deal with the output. I can see the XHR returning the values but chances are it's not actually being used as intended. – Simon at The Access Group Mar 26 '13 at 11:31
  • 1
    Please post only relevant code on jsfiddle, for example. Its kinda hard to find the issue in all your scripts. – Artyom Neustroev Mar 26 '13 at 11:34
  • 1
    [Please don't only link the buggy site](http://meta.stackexchange.com/q/125997/), but post the relevant code. – Bergi Mar 26 '13 at 11:41
  • Sorry, I will try and find the problem code, I am not sure what part to post but I will look now – matthew Mar 26 '13 at 11:44
  • Have posted, sorry I wasn't thinking been working all morning on this and my head is spinning a little! – matthew Mar 26 '13 at 11:49
  • Your response seems to be invalid, it is returning `//{"displayPrice":"£4.14 excl. VAT<\/strong>
    (£4.97 incl VAT)<\/span>"}` instead of `{"displayPrice":"£4.14 excl. VAT<\/strong>
    (£4.97 incl VAT)<\/span>"}`
    – Arun P Johny Mar 26 '13 at 11:55
  • also the response contentType is `text/html; charset=UTF-8` instead of `application/json` – Arun P Johny Mar 26 '13 at 11:58
  • As an aside, although the price updates when I change diameter or length, the quantity doesn't appear to be used, even though I can see the price in the JSON response taking quantity into account. I assume that's because there's still a // at the start of the JSON? Just seems odd that updates are happening, but not displaying what is sent back – barnyr Mar 26 '13 at 12:19
  • Thankyou for the help, I cannot find the // in my code anywhere though! – matthew Mar 26 '13 at 13:18
  • Actually the code seems ok in chrome so I think it's something else... – matthew Mar 26 '13 at 13:38
  • What server-side language is generating the JSON? The // prefix might be a security feature of that language. Does that prefix appear in any other JSON requests from the same server? – Carl Von Stetten Mar 26 '13 at 15:48
  • It's coldfusion that's generating the JSON. It doesn't appear anywhere else... – matthew Mar 26 '13 at 16:06
  • 1
    Check if the "Secure JSON" option is turned on in ColdFusion Administrator. "//" is the default prefix used when this option is enabled. If you want to keep the security feature enabled, you'll need to modify your JavaScript code to remove the // before processing the JSON. – Carl Von Stetten Mar 26 '13 at 16:47
  • Thankyou I shall investigate with our hosts. Appreciate your help, i will let you know how I get on! – matthew Mar 26 '13 at 17:07
  • Thankyou cvonner you have resolved this annoying issue! It was indeed a secure JSON setting on our server which was blocking the script from working properly. Much appreciated, voted uP! – matthew Mar 27 '13 at 09:17
  • Excellent! Glad to hear your issue is resolved. – Carl Von Stetten Mar 28 '13 at 19:26

1 Answers1

2

Looks like the results of http://www.xxxxxxxx.co.uk/pricecheck.cfc?method=getPrice&returntype=JSON&sku=2947&qty=7contains an error.

//{"displayPrice":"£2.87 excl. VAT<\/strong>
(£3.44 incl VAT)<\/span>"}

Notice the comment (double slash) that prefixes the JSON.

It also looks like $.getJSON will fail silently if the JSON contains a syntax error: Why does $.getJSON silently fail?

Community
  • 1
  • 1
Brandon Boone
  • 16,281
  • 4
  • 73
  • 100