... load a file?

Get help using Construct 2

Post » Tue Dec 06, 2011 6:49 pm

Okay, I'm stumped. No matter what I do, nothing works.

I tried these:
[code]
jQuery.ajax({
            type:"GET",
            url:this.file,
            dataType:"xml",
            success:function(xml){alert(xml);}
            });

jQuery.get("test.xml",function(xml){alert(xml);});

instanceProto.loadFile = function(file)
    {
        var request = null;
        if (window.XMLHttpRequest)
        {
            request = new XMLHttpRequest;
        }
        else
        {
            alert("XMLHttpRequest is not supported by your browser.");
        };
       
        if(!(request === null))
        {
            request.open("GET", file, true);
            request.onreadystatechange = function()
            {
               if (request.readyState == 4 /* complete */) {
                    if (request.status == 200 || request.status == 304) {
                    alert('Transfer complete. XML data updated.');
                    this.data = request.responseText;
                    this.ready = true;
               }
               else {
                    alert('An error occurred. Old XML data kept.');
                    this.ready = true;
               };
            };
            request.send();
            this.ready = false;
            };
        }
       
    }
[/code]

But nothing works. No data is loaded, hell, AJAX doesn't even complete the task. I don't even get the error popups when AJAX would fail to load a file.

I've tried all these locally as well as exported to dropbox.

So how the heck do you load a local (to the index.html) file? Because a lot hinges on this functionality.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Dec 07, 2011 10:37 am

L bump. Any ideas?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Dec 07, 2011 12:12 pm

maybe its a crossdomain issue, but then its strange that you dont get any alert
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Wed Dec 07, 2011 12:50 pm

Can't be crossdomain issue if the file is in the same folder as project.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Dec 07, 2011 11:42 pm

I'm really not sure, and this might be a dumb suggestion/question but shouldn't the jquery.get line be placed in instanceProto.onCreate ?
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Thu Dec 08, 2011 11:30 am

That's where I pasted all that code from.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Dec 08, 2011 1:39 pm

Then maybe instanceProto.loadFile should be out of that function, placed earlier/before onCreate. You call it in onCreate.Kyatric2011-12-08 13:41:01
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Thu Dec 08, 2011 1:56 pm

Oh, I mean I pasted the GET from onCreate, the instanceProto.loadFile is called from onCreate. Sorry I wasn't clearer. I'm not that dumb :)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Dec 08, 2011 2:10 pm

Sorry I doubted you.
I'm afraid I can't be of any help on this.
Maybe @rexrainbow, @r0j0hound or @Ashley might help (if they don't mind too much the alerting ^^)
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Tue Mar 20, 2012 3:59 am

i know.

the request.send(); needs to be moved out one level of brackets..

you had it in the function which is only called when you get successful response but you wont get a response as you never send in the first place.

try moving it down a few lines
B
7
S
1
Posts: 65
Reputation: 821

Next

Return to How do I....?

Who is online

Users browsing this forum: Megavolt, mnashwan, shinkan, stylie1 and 18 guests