× Requests and support related to jBackend.

Access-Control-Allow-Origin

  • faustorossi
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #3440 by faustorossi
Access-Control-Allow-Origin was created by faustorossi
Hello, I created an app with angularJS, I get the following message:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4435' is therefore not allowed access.

Then I tried the following solution:
in ROOT\components\com_jbackend\views\request\view.html.php" i added
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");

Works on the first request, the next sequinte get the message:

XMLHttpRequest cannot load rachataxi.widesys.net.br/rest/post/user/updatelatlngorigin?api_key=HT83ZL860MC0V6GPNEFB. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4435' is therefore not allowed access. The response had HTTP status code 500.

I'm almost no sleep, please help me.

Please Log in or Create an account to join the conversation.

More
9 years 3 months ago #3442 by admin
Replied by admin on topic Access-Control-Allow-Origin
Hi,
of course I can help you.

The KISS solution for the Access-Control-Allow-Origin problem, assuming this is restricted to development (localhost) scenario is to use (like I do) a Chrome extension to ignore this:

chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

About the error message on the second request, you should take a look at your error log and check the message for the error 500. But if I call your URL I get:
1452 - Cannot add or update a child row: a foreign key constraint fails (`widesysn_rachataxi`.`tax_users_location`, CONSTRAINT `fk_userslocation_user_id_users_id` FOREIGN KEY (`user_id`) REFERENCES `tax_users` (`id`)) SQL=INSERT INTO `tax_users_location` (`user_id`,`lat_origin`,`lng_origin`,`lat_destiny`,`lng_destiny`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`) VALUES ('0','0','0','0','0','2015-01-09 08:37:58','0','','0000-00-00 00:00:00','0')

And this is a clear message of a key violation on MySQL, so maybe the second time the problem is not the jBackend response, but the application logic before...

Kind regards,
Luigi

Please Log in or Create an account to join the conversation.

  • faustorossi
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #3443 by faustorossi
Replied by faustorossi on topic Access-Control-Allow-Origin
Thanks for the feedback, look what I found out about the second error:
On the browser, login with step 1 and update and localization with the 2nd step ..

STEP 1º - rachataxi.widesys.net.br/rest/post/user/login?username=a@a.com&password=admin&api_key=HT83ZL860MC0V6GPNEFB

STEP 2º - rachataxi.widesys.net.br/rest/post/user/login?username=a@a.com&password=admin&api_key=HT83ZL860MC0V6GPNEFB

Will work perfectly, but when I do the same steps for the webapp "jQuery or AngularJS POST", I found that the Step 2 failure "foreign key constraint fails" by the user is not logged into the server, ask:

All and any operation that is done, I need to always login the user?

Thanks

Please Log in or Create an account to join the conversation.

  • faustorossi
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #3446 by faustorossi
Replied by faustorossi on topic Access-Control-Allow-Origin
Just complementing, I made two videos explaining the 2 steps:

STEP 1 - Test with a browser, the user keeps logged and can do other operations.
rachataxi.widesys.net.br/images/Untitled%20Screencast%20(4).webm

STEP 2 - Test with webapp, you DO NOT Keep logged in.
rachataxi.widesys.net.br/images/Untitled%20Screencast%20(5).webm

Any idea why user is not logged in when WEBAPP use?

Thanks

Please Log in or Create an account to join the conversation.

More
9 years 3 months ago - 9 years 3 months ago #3447 by admin
Replied by admin on topic Access-Control-Allow-Origin
Ok,
Joomla login is based on the session cookie. Initially I tried to add an option to pass the session token also as request param, but Joomla do not support this in the core code (I can't override). So you need to be sure that your webapp stores and sends the session data on each request, like:
Cookie:d7817c7ee8c67579a593ac8e18ea3270=bneg53m0i1f7qpisai3hqjp416; _gat=1; _ga=GA1.2.53378032.1421228319

If not, this is your problem. Please, verify and if the problem persists even with session data let me know.

Kind regards,
Luigi
Last edit: 9 years 3 months ago by admin.

Please Log in or Create an account to join the conversation.

  • faustorossi
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 3 months ago #3450 by faustorossi
Replied by faustorossi on topic Access-Control-Allow-Origin
Hello, thanks for the reply, it was good.
I left a question of how to send the session cookie data in joomla google groups, if you have an example and can pass me.

PS: In login I'm already returning session_name, session_id, cookie_value, now do not know how to send them joomla.

If you can help me thank you very much.

Please Log in or Create an account to join the conversation.

Time to create page: 0.174 seconds