Problems with POST request from cocos to webpage

Cocos2d-x JavaScript Networking
  • tjjoss
    Likes 0

    Problem Description

    I have a question relating the POST request. I implemented the code provided to communicate to a web page (where my cocos game is hosted) and I'm having a couple of problems:

    1. The webpage receiving the post request does not reflect the changes that are supposed to be shown when I call it. When I click elsewhere (ie, another section of the webpage) the changes are correctly shown. So it's like the cocos2d game gets the http response instead of the browser, and so the changes are not shown (even though they have been applied). 
    2. And this might be related to the previous question, the communication was working fine over http but when I switched to https, the webpage doesn't seem to be responding to my requests even though I get a 200 response back along with the complete html response. This means that now, even if I click on other parts of the webpage, the changes are not being applied. Any help would be greatly appreciated.

    To make it a little bit more clear. This is the code I’m using:

            var xhr = cc.loader.getXMLHttpRequest();
            var url = "/?add-to-cart=8&ref=";
            url += conf;

            xhr.open( "POST", url );
            xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
            xhr.send();
                                          
            xhr.onreadystatechange = function ()
            {
                if ( xhr.readyState == 4 && ( xhr.status >= 200 && xhr.status <= 207 ) )
                {
                    var httpStatus = xhr.statusText;
                    cc.log(sTime() + " [AnimationLayer] Status: " + httpStatus);

                    var response = xhr.responseText;
                    cc.log(sTime() + " [AnimationLayer] Response: " + response);
                }
            }

     

    As you can see, nothing fancy, it’s practically what you showed on your video. I’m calling the "/?add-to-cart=8&ref=" url (over https) with some parameters in the query string (ie the item to add to the cart) . The log output of that code is: 

    12:11:19 [AnimationLayer] Status: OK
    12:11:19 [AnimationLayer] Response: <!DOCTYPE html>
    <html class="html" lang="en-US">
     <head>

      <script type="text/javascript">
       if(typeof Muse == "undefined") window.Muse = {}; window.Muse.assets = {"required":["museredirect.js", "jquery-1.8.3.min.js", "museutils.js", "jquery.watch.js", "index.css"], "outOfDate":[]};
    </script>

    So, I’m definitely getting a response, and it seems valid, but the browser is not showing any of the changes it supposedly received (ie, a new item added to the cart). 
    What’s wrong then?
  • Sonar Systems admin
    Likes 0

    Can you show is a video of what is happening.

Login to reply