Quantcast
Channel: Foren
Viewing all articles
Browse latest Browse all 170

Intel XDK WP 8 upport for XMLHttpRequest does not work properly for cross-domain requests

$
0
0

The XDK's WP 8 Beta support has an issue with XMLHttpRequests to an external domain. This problem only occurs on the WP 8 platform. The XMLHTTPRequests properly on the Android and iPhone platforms.

The response I receive on WP 8 is an error response and the status code is 0 which doesn't make sense.

The example code is shown below.

Please note that the API URL has been intentionally set to a dummy URL to protect the company's server API. If you're with Intel, please feel free to contact me confidentially for the actual URL I used to test out the XDK's XMLHttpRequest support.

Thanks in advance.

<!DOCTYPE html>
<html class="ui-mobile-rendering">
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv='Content-Type' content='Type=text/html; charset=utf-8'>

    <style>
        html {
            background-color: #ffffff;
        }

        #console {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: 0;
            padding: 0;
            overflow-x: hidden;
            overflow-y: auto;
        }

        #console p {
            margin: 0;
            padding: 0;
        }
    </style>

    <!-- AppMobi-specific scripts -->
    <script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/appmobi.js"></script>
    <script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/xhr.js"></script>
    <script type="text/javascript">
        var consoleDiv;

        function writeConsole( message ) {
            var messageElem;

            messageElem             = document.createElement( "p" );
            messageElem.innerText   = message;
            consoleDiv.appendChild( messageElem );
        }

        function start() {
            consoleDiv = document.getElementById( "console" );

            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4){
                    writeConsole( "FETCH DONE ---" );
                    writeConsole( "Text: " + xhr.responseText );
                    writeConsole( "Headers:\n" + xhr.getAllResponseHeaders() );
                    writeConsole( "Status: " + xhr.status );
                    writeConsole( "Status text: " + xhr.statusText );
                }
            };
            xhr.onerror = function( event ) {
                writeConsole( "AJAX error: " + JSON.stringify(event, null, 2) );
            };
            xhr.ontimeout = function( event ) {
                writeConsole( "AJAX timeout: " + JSON.stringify(event, null, 2) );
            };
            xhr.open( "GET", "http://thelocation.com/", true );
            xhr.send();
        }
    </script>
</head>

<body onload="start()">
<div id="console"></div>
</body>

</html>


Viewing all articles
Browse latest Browse all 170

Trending Articles