开发者

ajax wont change the specified value onSucess call

this project is is hosted on shopify but i will explain what everything does so you dont need to know how shopify works.

here is the site i'll be referring to. ( http://www.republicway.myshopify.com/collections/united-states ) regarding the stars you see and their readonly on this page.

i'm using a star rating system called (JRating)

here is the section i'm having a problem with. as you can see in the code im trying to set data equal a value received from my localhost the value does come through i have tried with alert. but it wont set the numeric value in data. what basically is happen is the gets rendered through the jrating library found on the bottom of the page that i provided then using ajax i set the data value based on the id sent over. the id does coem back with a value via json but it wont work for some reason. i have also tried regular html to see if the rating works and it did.

<div id="spinner" style='display:none;'> <img src="{{ 'spinner.gif' | asset_url  }}"> </div>

    <div class="rating" ></div>
    <script type="text/javascript">
    $(document).ready开发者_如何学C(function() 
    {

        $.ajax({
            url: 'http://69.231.223.112:8888/shopify/shopifyajax.php?jsoncallback=?',
            type: 'GET',
            data: 'page=collection&id={{ product.id }}', //shopify command displays a number like 11202
            dataType: "json",


            beforeSend: function() 
            {
                $("#spinner").show();
                $(".rating").attr("data", '0');

            },
            complete: function() 
            {
                $("#spinner").hide();
            },
            success: function(result) 
            {
                    var value = parseInt(result.rvalue);
                    $(".rating").attr("data", value);

            },

        });

    });

    </script>


Is this site (from what you want get JSON) on your host? As I know - cross-domain requests are forbidden.. You can use something like proxy for your request - get page from PHP (file_get_contents or other function) and do your request to this file (proxy.php or other) where this content is stored.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜