Ajax - Cross-domain widget request

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m currently trying to create a widget server which will serve widgets(duh), compareable to a google maps. Once the widget is loaded i will need to make additional calls to fetch more data if needed.
Since i m loading the widgets via an ajax call and not iframe(due to styling concerns) i m doing a cross domain call.
My question is fairly simple : how should i handle this?
I read about CORS and tried modifying my ajax response with an additional header :

Response.AppendHeader("Access-Control-Allow-Origin", "*");

but he doesn t even reach that line, my mvc project returns an empty result with statusCode 404 and status "Error".
At first he did an options call because i had content-type application/json but even text/plain does not reach my server.
Am I following the right approach? Should i embed my data as jsonp?
Feel free to share your insight.

Code that loads the widget :

$.ajax(
    {
        type: "GET",
        contentType: "text/plain",
        url:  http://someotherdomain/widget/1 ,
        crossDomain: true,
        dataType: "json",
        success:function(data) {
            $( #targetDiv ).html(data.htmlContent);
        },
        error: function(data) {
            alert( error... );
        }
    });

Answers

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/20050878/cross-domain-widget-request

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils