* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Problem with XMLHttpRequest with AJAX  (Read 1609 times)

0 Members and 1 Guest are viewing this topic.

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Problem with XMLHttpRequest with AJAX
« on: November 16, 2015, 01:51:55 am »
I'm having a problem with this code. I've been debugging it for hours already. Why isn't the XML parsing and displaying?

Code:
Code: [Select]
//Get the latest technology news from the internet

//Fetch the RSS feed
var request = new XMLHttpRequest();
var xmlDoc;

request.open("GET", "http://www.winbeta.org/feed", true);
request.send();

if(request.readyState == 4)
{
xmlDoc = request.responseXML;
}

personOneTalk.innerHTML = xmlDoc;


  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

Offline Adriweb

  • Full User
  • CodeWalrus Supporter
  • *
  • Join Date: Jan 2015
  • Location: France & Canada
  • Posts: 393
  • Post Rating Ratio: +6/-0
    • Adriweb
    • @Adriweb
    • Adriweb
    • @UC-UIrbk5SuaUCvnV6SQvt-Q
    • /u/Adriweb
    • Adriweb
    • View Profile
    • TI-Planet.org
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #1 on: November 16, 2015, 01:57:08 am »
The first thing to do is to look at the JS console and see what's wrong. What have you been doing "for hours" ??!

For me, I had two things :
1) "Mixed Content: The page at 'https://codewalr.us[...]' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.winbeta.org/feed'. This request has been blocked; the content must be served over HTTPS."
That was solved by actually requesting the feed from HTTPS. You don't want to use HTTP anyway.

2) XMLHttpRequest cannot load https://www.winbeta.org/feed. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://codewalr.us' is therefore not allowed access.
Standard CSRF protection, I'll let you read up on that (example of a solution: making the XHR through a local PHP (or whatever) proxy fetching the remote content for you).
  • Calculators owned: TI-Nspire CX CAS, TI-Nspire CX, TI-Nspire CAS (x3), TI-Nspire (x2), TI-Nspire CM-C CAS, TI-Nspire CAS+, TI-80, TI-82 Stats.fr, TI-82 Plus, TI-83 Plus, TI-83 Plus.fr USB, TI-84+, TI-84+ Pocket SE, TI-84+ C Silver Edition, TI-84 Plus CE, TI-89 Titanium, TI-86, TI-Voyage 200, TI-Collège Plus, TI-Collège Plus Solaire, 3 HP, some Casios
Co-founder & co-administrator of TI-Planet and Inspired-Lua

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #2 on: November 16, 2015, 01:59:42 am »
I have an extension in Google Chrome that takes care of the "Access-Control-Allow-Origin" header problem
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #3 on: November 16, 2015, 02:36:35 pm »
I have this code:
Code: [Select]
//Get the latest technology news from the internet

//Fetch the RSS feed
var request = new XMLHttpRequest();
var xmlDoc;

if(typeof request.overrideMimeType != "undefined")
{
request.overrideMimeType("text/xml");
}

request.open("GET", "http://www.winbeta.org/feed", true);
request.send();

request.onreadystatechange = function()
{

if(request.readyState == 4 && request.status == 200)
{
var xmlDoc = request.responseXML;

personOneTalk.innerHTML = "Sure! Have you heard of " + xmlDoc;
}

else
{

}

};

and I get the result:
Sure! Have you heard of [object XMLDocument]

How do I parse this?

Update: problem solved!!!!
« Last Edit: November 16, 2015, 04:25:02 pm by Ephraim Becker »
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

Offline DJ Omnimaga

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Topic Management
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 17425
  • Post Rating Ratio: +83/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • View Profile
    • DJ Omnimaga music store
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #4 on: November 16, 2015, 06:25:18 pm »
How did you solve the problem?
  • Calculators owned: TI-73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX, HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Streetwalrus

  • Professional slacker
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Original 5
  • Join Date: Nov 2014
  • Location: Israel
  • Posts: 2780
  • Post Rating Ratio: +19/-0
  • ƎW∀⅁ ƎH⊥
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #5 on: November 16, 2015, 07:32:13 pm »
I have an extension in Google Chrome that takes care of the "Access-Control-Allow-Origin" header problem
This is fine for development purposes, but don't expect your users to have the extension installed for it to work.
  • Calculators owned: TI-80, HP 40G, TI-84 Plus rev G (yay 128k RAM), TI-83 Plus Silver Edition (broken LCD), TI-82 Stats.fr (black), TI-Nspire CX rev C (yay Nlaunchy), TI-83+ SE ViewScreen

Offline DJ Omnimaga

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Topic Management
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 17425
  • Post Rating Ratio: +83/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • View Profile
    • DJ Omnimaga music store
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #6 on: November 16, 2015, 07:56:51 pm »
Yeah, that's my main concern here. When developing or using softwares, you have to use the "I need to adapt to other people" philosphy, not "Other people needs to adapt to me". So you need to ensure that your softwares requires as few dependencies as possible because many people will not force themselves to install a new obscure extension just to use your software, let alone switching browsers.
  • Calculators owned: TI-73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX, HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #7 on: November 18, 2015, 12:30:06 am »
Is there a way to get around the access-control-allow-origin using only JavaScript?
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

Offline Streetwalrus

  • Professional slacker
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Original 5
  • Join Date: Nov 2014
  • Location: Israel
  • Posts: 2780
  • Post Rating Ratio: +19/-0
  • ƎW∀⅁ ƎH⊥
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #8 on: November 19, 2015, 04:41:52 pm »
No, it's a security feature used to make sure requests can't be made across different sites.
  • Calculators owned: TI-80, HP 40G, TI-84 Plus rev G (yay 128k RAM), TI-83 Plus Silver Edition (broken LCD), TI-82 Stats.fr (black), TI-Nspire CX rev C (yay Nlaunchy), TI-83+ SE ViewScreen

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #9 on: November 20, 2015, 02:05:12 pm »
Should I go with JSONP? GitHub Pages doesn't support server-side programming languages so I have no choice but to do this in JavaScript.


Edit: I'm very confused about CORS. If CORS allows you to request other sites, then why can't I. I'm only able to do this in IE 11 locally.
« Last Edit: November 20, 2015, 08:32:58 pm by Ephraim Becker »
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

Offline Travis

  • Full User
  • Safe-haven access
  • Join Date: Jan 2015
  • Location:
  • Posts: 117
  • Post Rating Ratio: +3/-0
    • 8361
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #10 on: November 20, 2015, 10:37:59 pm »
I'm very confused about CORS. If CORS allows you to request other sites, then why can't I. I'm only able to do this in IE 11 locally.

The way I understand it, the site you're trying to request content from has to set up their web server to send a header that tells the browser it's okay to receive requests from your site. Unless you own the remote site you're requesting from, that's probably not going to happen.

What in particular was wrong with some of the solutions people suggested in other threads? I may have overlooked something, but it seems like I keep reading about you running into various problems, solving them, but without saying anything at all about how you solved them, whether the suggestions people gave you are helpful, or exactly what you're trying to do right now. Without that information, we are all completely in the dark.
« Last Edit: November 20, 2015, 10:40:17 pm by Travis »
  • Calculators owned: TI-81, TI-82, TI-85, TI-86, TI-89, TI-89 Titanium, 2 × HP 50g
ticalc.org staff member—http://www.ticalc.org/

Offline DJ Omnimaga

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Topic Management
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 17425
  • Post Rating Ratio: +83/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • View Profile
    • DJ Omnimaga music store
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #11 on: November 20, 2015, 11:35:02 pm »
I think he goes all-out trying to do things exactly the way he wants, so as a result, he seeks for ways to circumvent limitations to his solution instead of finding alternate solutions. However, he has to realize that life doesn't work that way and accept to do things differently sometimes, else he won't get very far when coding.
  • Calculators owned: TI-73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX, HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #12 on: November 22, 2015, 01:52:16 am »
I just read up on CORS again and it said that access-control-allow-origin has to be enabled on the server that i'm accessing it from. Since i'm not in control of the server i'm trying to access, I need to find RSS feeds with CORS enabled. Does anyone know of any?
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

Offline allynfolksjr

  • New User
  • Join Date: Dec 2014
  • Location:
  • Posts: 18
  • Post Rating Ratio: +0/-0
  • General Systems Vehicle
    • View Profile
Re: Problem with XMLHttpRequest with AJAX
« Reply #13 on: November 22, 2015, 02:29:07 am »
What's your overall objective here?

Offline Ephraim Becker

  • Full User
  • Join Date: Mar 2015
  • Location: Far Rockaway, NY
  • Posts: 118
  • Post Rating Ratio: +0/-4
    • @UCIHxAXYLxYlNaQiv0do0bUg
    • EphraimB
    • 112/11290
    • View Profile
  • Gender: Male
Re: Problem with XMLHttpRequest with AJAX
« Reply #14 on: November 22, 2015, 02:31:40 am »
Trying to get my Virtual Friend(http://ephraimb.github.io/Virtual-Friend) to fetch an RSS feed from the internet and have a conversation based on that. The problem is I dont see any RSS feeds supporting CORS.


Edit: MSN has CORS enabled but it returns an error:

XML5608: Semicolon expected.
Line: 11, Column 130
« Last Edit: November 22, 2015, 08:20:55 pm by Ephraim Becker »
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games