Working code snippet for local!!! file ajax issue in wp8

Bugs will be moved here once resolved.

Post » Sat Mar 08, 2014 5:13 am

modification at C:\Program Files\Construct 2\exporters\html5\plugins\ajax\runtime.js
makes local!!! file ajax in wp8 works well. (commented 6 //cranberrygame comments)

this code snippet is for previous issue
please-reconsider-local-file-ajax-issue-in-wp8_t97991
viewtopic.php?t=97280

thanks

...
try
{
//request = new XMLHttpRequest();//cranberrygame (1/6)
request = new ActiveXObject("Microsoft.XMLHTTP");//cranberrygame (2/6)
request.onreadystatechange = function()
{
if (request.readyState === 4)
{
self.curTag = tag_;

if (request.responseText)
self.lastData = request.responseText.replace(/\r\n/g, "\n"); // fix windows style line endings
else
self.lastData = "";

if (request.status >= 400)
self.runtime.trigger(cr.plugins_.AJAX.prototype.cnds.OnError, self);
else
{
// In node-webkit, don't trigger 'on success' with empty string if file not found
if (!isNodeWebkit || self.lastData.length)
self.runtime.trigger(cr.plugins_.AJAX.prototype.cnds.OnComplete, self);
}
}
};

//request.onerror = errorFunc;//cranberrygame (3/6)
//request.ontimeout = errorFunc;//cranberrygame (4/6)
//request.onabort = errorFunc;//cranberrygame (5/6)
//request["onprogress"] = progressFunc;//cranberrygame (6/6)

request.open(method_, url_);

// Workaround for CocoonJS bug: property exists but is not settable
try {
request.responseType = "text";
} catch (e) {}

if (method_ === "POST" && data_)
{
if (request["setRequestHeader"])
{
request["setRequestHeader"]("Content-Type", "application/x-www-form-urlencoded");
}

request.send(data_);
}
else
request.send();
}
catch (e)
{
errorFunc();
}
...
Construct2 Cordova Plugins (currently 87 plugins): https://www.scirra.com/store/construct2 ... ugins-1662

Construct2 Prototype Capx (currently 50 capx): https://www.scirra.com/store/games-with ... -capx-3088

Home page: http://cranberrygame.com
B
65
S
22
G
81
Posts: 780
Reputation: 46,631

Post » Wed Mar 12, 2014 8:07 pm

Alright, this works, but is non-standard. I've enabled that workaround code for Windows Phone 8 only and it seems to work. All other platforms will keep using the old standards-compliant code.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,600


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests