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

I used i18n plugin for load *.properties file for translation and its working fine on android platform

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745135294a4613170.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信