最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cross Origin in ajax not working for .properties file in IOS (10.3.1) - Stack Overflow

programmeradmin2浏览0评论

I used i18n plugin for load *.properties file for translation and its working fine on android platform but same library not working on IOS 10.3.1. It gives me below error:

i have done some changes in i18n library but still its not working.

function loadAndParseFile(filename, settings) {
    $.ajax({
        url: filename,
        async: false,
        cache: settings.cache,
        crossDomain: true,
        jsonpCallback: 'callback',
        contentType: 'text/plain;charset=' + settings.encoding,
        dataType: 'text',
        success: function (data, status) {
            parseData(data, settings.mode);
        }
    });
}

In above code:

i have been added Cross-Domain 'true' and datatype 'text'.. when i changed datatype 'text' to 'jsonp' its working but it gives .properties file error. Please check below error..

That means. file is loaded, but inner data format is different.

I used i18n plugin for load *.properties file for translation and its working fine on android platform but same library not working on IOS 10.3.1. It gives me below error:

i have done some changes in i18n library but still its not working.

function loadAndParseFile(filename, settings) {
    $.ajax({
        url: filename,
        async: false,
        cache: settings.cache,
        crossDomain: true,
        jsonpCallback: 'callback',
        contentType: 'text/plain;charset=' + settings.encoding,
        dataType: 'text',
        success: function (data, status) {
            parseData(data, settings.mode);
        }
    });
}

In above code:

i have been added Cross-Domain 'true' and datatype 'text'.. when i changed datatype 'text' to 'jsonp' its working but it gives .properties file error. Please check below error..

That means. file is loaded, but inner data format is different.

Share Improve this question edited Jan 20, 2020 at 5:14 ankitkanojia 3,1224 gold badges24 silver badges37 bronze badges asked Jun 23, 2017 at 9:33 user6390636user6390636 11
  • Yes, the log tells you that the Messages.properties file is invalid ("Unexpected identifier 'User'). Is this a static file or generated? Either way: You need to fix it. – Wukerplank Commented Jun 23, 2017 at 9:39
  • @Wukerplank Yes, Its Static file.. – user6390636 Commented Jun 23, 2017 at 9:44
  • Are you passing a valid URL here... $.ajax({ url: filename, ... })? – user3451822 Commented Jun 27, 2017 at 13:01
  • @joshuamabina.. Yes.. URL is Valid.. its file path – user6390636 Commented Jun 28, 2017 at 7:22
  • @Goku you should put that file on your server and then try to access it from the server. IOS has different file structure than windows. That is why it is working on windows and not on IOS and AJAX call needs a protocol work – Shubham Commented Jul 3, 2017 at 6:47
 |  Show 6 more ments

2 Answers 2

Reset to default 1

add this line to your ajax parameters

xhrFields: {
    withCredentials: true
}

If you are using now JSONP instead of text, the file will be loaded as javascript code, so if contents are not valid javascript code it will fail.

Surround data with a global variable assignation or a function call:

    window.variable = "_DATA_"; // or
    functionName("_DATA_");

If _DATA_ are JSON format, then you don't need surround with quotes, otherwise you'll need to use "_DATA_" because without quotes it will not be valid javascript syntax.

发布评论

评论列表(0)

  1. 暂无评论