Jump to content

Pages Web Service issue


Manol
 Share

Recommended Posts

I run into a problem, when I paste http://benipeixcar.indinet.es/service-pages/?parent=1013 I get json data from pages web service, but when I do it from a page generated with "yo angular" I get the following error, anybody with same or similar problem?

OPTIONS http://benipeixcar.indinet.es/service-pages/?parent=1013 Origin http://127.0.0.1:9000 is not allowed by Access-Control-Allow-Origin.

angular.js:9499

XMLHttpRequest cannot load http://benipeixcar.indinet.es/service-pages/?parent=1013. Origin http://127.0.0.1:9000 is not allowed by Access-Control-Allow-Origin.

Link to comment
Share on other sites

Not exactly sure if this is the same issue, but I have used this script (http://benalman.com/code/projects/php-simple-proxy/examples/simple/) in several cases and it works great.

Here is a direct link to your web service output:

http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fbenipeixcar.indinet.es%2Fservice-pages%2F%3Fparent%3D1013&full_headers=1&full_status=1

You should probably host the proxy file yourself though.

  • Like 1
Link to comment
Share on other sites

Hi Manol,

if you want to get by an ajax call your URL you must set the header "Access-Control-Allow-Origin: *" where the "*" can be one or more domains; the asterisk says: "Anyone can access to this URL by an ajax call".

Not sure if the module Pages Web Service has an option to set that HTTP header.

Alessio

  • Like 1
Link to comment
Share on other sites

Thank you.

   When I make the call within the same host it works, but if I call the service from a different url it fails.

   Interesting Adrian's solution I'll give it a try and Alessio I don't know either if it's possible to set Access-Control-Allow-Origin: * to the Web Service, anyway is a starting point both ideas.

Link to comment
Share on other sites

I think you can enable Cross-domain AJAX requests in your .htaccess
 
# ------------------------------------------------------------------------------
# | Cross-domain AJAX requests |
# ------------------------------------------------------------------------------
 
# Enable cross-origin AJAX requests.
# http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
# http://enable-cors.org/
 
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>

found in html5-boilerplates .htaccess

  • Like 4
Link to comment
Share on other sites

In the end was an angularjs problem, two steps to solve it

First: adding that piece of code to my .js

angular.module('myApp')
.config(function($httpProvider){ 
$httpProvider.defaults.useXDomain=true;
delete $httpProvider.defaults.headers .common['X-Requested-With']; });
Second: adding what interrobang says to .htaccess
# ------------------------------------------------------------------------------# | Cross-domain AJAX requests |# ------------------------------------------------------------------------------ # Enable cross-origin AJAX requests.# http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity# http://enable-cors.org/ <IfModule mod_headers.c>Header set Access-Control-Allow-Origin "*"</IfModule> 
Thanks to everybody.
  • Like 4
Link to comment
Share on other sites

The solution in the last post works on any browser but mobile ones, I've tried on android and iphone and couldn't get json data back from the server, in the end I had to install the web embedded on the same host, the one that proportionates the data and the one that consumes it.

 http://myurl.com  gives de web-page service and I have installed   http://myurl.com/site/templates/anotherweb to access data from mobiles browsers, if you don't need to access the page from mobile phones the solution up works on http://anyurl.com

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...