0

I have a problem with my project. This is my idea:

  • Bypass CORS to another domain with JSONP: I do it !
  • Converted XML to JSONP: Because data in domain is XML.
  • Do something with this data as a XML file.

The problem is: it always return: Unexpected token <. I know it can't read XML as JSONP DataType. But in my opinion, JS can converted XML to JSONP, if it's right. Please suggest me how to use it.

This is my code:

function test(){
    $.ajax({
    type: 'GET',
    dataType: "jsonp",
    processData: true,
    crossDomain: true,
    jsonp: true,  
    url: "http://huysoi.com/den.xml",
    //converters: {"xml": jQuery.parseXML},
    username: 'admin',
    password: 'admin',
    success: function (responseData, textStatus, jqXHR) {
        console.log('in');
    },
    error: function (responseData, textStatus, errorThrown) {
        alert('POST failed.');
    }
});

<input type="button" onclick="return test();" >

enter image description here

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
huy cao
  • 28
  • 8

1 Answers1

0

It won't work. You can't send ajax request for xml with jsonp. I had the same problem and finally I used post messaging with iframe for solving the cross domain problem

see https://github.com/ofirdagan/cross-domain-local-storage

Dusty
  • 354
  • 4
  • 15
  • Can you share with me? Thank you so much. I'm so headache with this problem >. – huy cao Jun 04 '15 at 08:37
  • Sure. I used the https://github.com/ofirdagan/cross-domain-local-storage . You need to create iframe and then add post messaging for passing xml with local storage – Dusty Jun 04 '15 at 08:39
  • Does it work with basic protected domain ??? – huy cao Jun 04 '15 at 08:46