Author Topic: CORS request failed  (Read 16835 times)

williamsj

  • Newbie
  • Posts: 5
  • I'm a llama!
    • View Profile
CORS request failed
« on: August 26, 2015, 07:36:14 PM »
Hi,

I'm having a bit of trouble trying to program some jave/html using a couple of FMD's. I realise this is primarily a plc programming site but hopefully someone can give me a hint.

I have 2 PLC's, plc1 and plc1. Plc1 is acting as a web server and plc2 for data collection. It has to be this way.

The problem is when browsing to plc1 and having that web page try to get data from plc2, using XMLHttpRequest and host link protocol format, I'm getting the CORS request failed, found using Firefox and Firebug.

It appears from reading that the web server needs to have "Access-Control-Allow-Origin:" appended to it's html header and I gather this doesn't occur.

Can anyone help in this area?

cheers,

john
There are 10 types of people that understand binary,
those who do and those who don't

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:CORS request failed
« Reply #1 on: August 26, 2015, 08:54:33 PM »
Browser security policy normally only allows webpage to interact with the origin from which it is loaded (same origin). It is not easy to get around that (as it should since cross site scripting attack is what the browser is trying to prevent).

If both PLC1 and PLC2 are connected to the LAN, PLC2 may be programmed to periodically write the data it collected to DMs area in PLC1 using the <CONNECT> tag or <MBTCPCONNECT> tag. That way the DMs area in PLC1 will always have the latest data collected by PLC2. PLC1 can determine that a new data set is available by clearing a relay to indicate that the data has been read, and the PLC2 will set that relay when it writes a new set of data.

The web page launched from PLC1 can then access the DM area of PLC1 instead of trying to access the data in PLC2.
« Last Edit: August 26, 2015, 08:56:14 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

williamsj

  • Newbie
  • Posts: 5
  • I'm a llama!
    • View Profile
Re:CORS request failed
« Reply #2 on: September 02, 2015, 08:56:58 PM »
Hi,

Yea, I get why it's like it is. And I guess there's no real reason to change the PLC web server just to support something that's very seldom needed.

I thought of getting the data from plc2 via plc1 like you suggested.

thanks for the response,

cheers,

john
There are 10 types of people that understand binary,
those who do and those who don't

davidg

  • Newbie
  • Posts: 11
    • View Profile
    • My Mobile HMI | Connect a mobile App to your PLC
Re:CORS request failed
« Reply #3 on: November 03, 2015, 02:39:38 PM »
Another simple option would be to use Google Chrome browser and use extensions that enable to CORS

Here is a link to one extension that adds a button that toggles CORS:

https://chrome.google.com/webstore/detail/cors-toggle/omcncfnpmcabckcddookmnajignpffnh?hl=en

After extension is installed, just press button to enable CORS (Transmission will not be blocked) then press again to go back to normal protected mode.