在.js文件上使用Ajax获取JSONP

I try to keep data from à json file with cross domain. So i use jsonp but the file have the extension .js, so when i try $.ajax with dataType : 'jsonp' i have an error in console: Uncaught SyntaxError: Unexpected token The file is interpret as a javascript file an the request fail. Have you an idea for get data whithout this error.

$.ajax({
    url : 'http://domaine.com/file.js',
    contentType: "application/json; charset=utf-8",
    dataType : 'jsonp',
    success : function(data){
        console.log(data);
        // no enter in this callback
    },
    complete: function(data1, data2, data3){
        // no data from file.js
    }
});

I found file.js when i inspect page in scripts who are load an i can see all information, but with an error because it is considerate as javascript file.

Thanks for your help.

Convert your json to proper jsonp

jsonpcallback({"this":"is","my":"json"})

Then request it with the given callback:

<script>
    function jsonpcallback(data) {
        console.log(data);
    }
</script>
<script src="http://domain.com/file.js"></script>

You could of course do it with jQuery too:

$.ajax({
    url: "http://domain.com/file.js",
    dataType: "jsonp",
    jsonpCallback: "jsonpcallback",
    success: handler,
    complete: handler,
    error: handler
});