How can I use XMLHttpRequest on the mobile extension?

Hello :smiley:

Last year, I created a panel that take data from my DB using XMLHttpRequest of Javascript and the extension worked well in the PC environment for a year

So I wanted to make this panel into a mobile version and I put the panel in the mobile without modification, but it didn’t work

How can I use XMLHttpRequest on the mobile too?

Being on mobile is no different, though personally I use fetch and it’s working for me. If it’s not working for you, you might have something else going on

1 Like

Just in case, when I tested a mobile page on the web, it worked normally
I don’t think there’s a problem
Doesn’t it work when it’s not finally released?

The only difference between hosted test and release is who can see the extension*
The only difference between localtest and hosted test is where the files are

  • Some Twitch API’s not withstanding (live_activated_channels)

So Client Side code such as XMLHttpRequest works regardless of the state of the extension because it’s client side code

Twitch doesn’t block XMLHttpRequests from working so I don’t know what the problem is.

The only real rule is that the thing you are XMLHttpRequesting needs to be on SSL and support CORS, but thats the same regardless of if it’s on Mobile or Desktop

1 Like

My XML file is working based on PHP and the code about header is just

header('Content-Type: text/xml;charset=utf-8');
header('Access-Control-Allow-Origin: https://{Extension ID}.ext-twitch.tv');
header('Access-Control-Allow-Methods: POST');

Is there anything else I need to add?

Looks correct to me.

1 Like

:disappointed_relieved:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
    if(this.readyState == 4 && this.status == 200) {
        ...
}
xhr.open("POST", "{XML URL}", true);
xhr.send();

It’s Javascript code
Is there any problem here too?

looks good

Like you said it works on PC, there is no reason it should work on mobile in the app instead, there is no difference between the platforms here.

Could be something obscure like your server is suggesting SSL ciphers not compatible with iOS/Android and the connection derps out. But it’s not a Twitch Extensions issue, it’s something awry with your implementation on either end

But thats the clutching at straws for possibles, as if the code works in a browser and it’s as basic as this it shouldn’t not work

1 Like

Ok thanks for your help :smiley: