Cross domain access for JSON interface using AJAX

Bug #816607 reported by Sneetsher on 2011-07-26
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Alfanous - Quranic Search engine
Fix Released
High
Assem Chelli (عاصم شلي)

Bug Description

Salam,

I'm using Chromium 12.0.742.112 (90304) Ubuntu 10.04.

Trying to access Alfanous JSON interface from JavaScript (jQuery). The browser prevents my script from retrieving data.

chromium js console:
XMLHttpRequest cannot load http://www.alfanous.org/json?search=%D8%A3%D8%AD%D9%85%D8%AF. Origin null is not allowed by Access-Control-Allow-Origin.

As it is mentioned here:
http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin

A workaround is to add callback= to GET parameters

Otherwise:
server reply must have 'Access-Control-Allow-Origin: *' in the HTTP header.

Changed in alfanous:
assignee: nobody → Assem Chelli (عاصم شلي) (assem-ch)
importance: Undecided → Critical
status: New → Incomplete
status: Incomplete → New

Salam ,

First ,thank you for submiting this bug. as i read it's about the browsers policy that restrict getting information from other websites.

I added this header to the service script:
    print "Content-Type: application/json; charset=utf-8"
    #Allow cross domain XHR
    print 'Access-Control-Allow-Origin: *'
    print 'Access-Control-Allow-Methods: GET'
    print

Also I added this to .htaccess :
    Header set Access-Control-Allow-Origin *

I hope this helps.

Changed in alfanous:
importance: Critical → High
Sneetsher (sneetsher) wrote :

Yeah, it is working well now. Thank you.

Changed in alfanous:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers