XMLHttpRequest cannot load http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=cat. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
Refused to set unsafe header "Origin"
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
For a CORS request to be allowed by the remote wiki, $wgCrossSiteAJAXdomains must be set appropriately to allow the origin site. The MediaWiki API also requires that the origin be supplied as a request parameter, appropriately named "origin", which is matched against the Origin header required by the CORS protocol. Note that this header must be included in any pre-flight request, and so should be included in the query string portion of the request URI even for POST requests.
If the CORS origin check passes, MediaWiki will include the Access-Control-Allow-Credentials: true header in the response, so authentication cookies may be sent.
On Wikimedia wikis CORS is enabled since September 2012; as of October 2013 CORS pre-flight requests are also supported.
You can't set the header yourself, the browser will do that. However you should be able to add that query string parameter yourself.
--
import Html exposing (Html, div, text, input)import Html.Attributesimport Html.Events exposing (on, targetValue)import Http exposing (Error, get)import Task exposing (Task, succeed, fail, andThen, mapError)import Json.Decode as Decode exposing (Decoder, tuple4, list, string)import Signal exposing (Signal, Mailbox, mailbox, message, send)import List
----crossOriginGet : String -> String -> Task Http.RawError Http.ResponsecrossOriginGet origin url = Http.send Http.defaultSettings { verb = "GET" , headers = [ ("Origin", origin) , ("Content-Type", "application/json; charset=UTF-8") ] , url = url , body = Http.empty }
corsGet : String -> String -> Decoder value -> Task Error valuecorsGet origin url decoder = Http.fromJson decoder (crossOriginGet origin url)
----
type alias WikipediaRequestJson = ( String , List String , List String , List String )
type alias WikipediaSearchTermRequest = { term : String , results : List WikipediaSearchTermResult }
type alias WikipediaSearchTermResult = { term : String , description : String , url : String }
emptyRequest : WikipediaSearchTermRequestemptyRequest = WikipediaSearchTermRequest "" []
fromJson : WikipediaRequestJson -> WikipediaSearchTermRequestfromJson (term, results, descriptions, urls) = WikipediaSearchTermRequest term (List.map3 WikipediaSearchTermResult results descriptions urls)
wikipediaRequest : Decoder WikipediaRequestJsonwikipediaRequest = tuple4 (,,,) string (list string) (list string) (list string)
getWikipediaSearchTerm : String -> Task Error ()getWikipediaSearchTerm term = let wikiurl = in corsGet "localhost:8000" wikiurl wikipediaRequest `andThen` (fromJson >> send wikipediaTermMailbox.address)
termSearchMailbox : Mailbox (Task Error ())termSearchMailbox = mailbox (succeed ())
wikipediaTermMailbox : Mailbox WikipediaSearchTermRequestwikipediaTermMailbox = mailbox emptyRequest
model : Signal WikipediaSearchTermRequestmodel = wikipediaTermMailbox.signal
view model = div [] [ input [ on "input" targetValue (message termSearchMailbox.address << getWikipediaSearchTerm)] [] , text (toString model) ]
port termSearch : Signal (Task Error ())port termSearch = termSearchMailbox.signal
main : Signal Htmlmain = Signal.map view model
--