Cross Origin in ajax not working for .properties file on IOS (10.3.1)

I used the i18n plugin to download the * .properties file for translation and its work on the Android platform, but the same library does not work on iOS 10.3.1. This gives me the error below:

enter image description here

I made some changes to the i18n library, but still does not work.

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 the above code:

i was added Cross Domain 'true' and datatype 'text' .. when I changed the data type 'text' to 'jsonp' it works, but it gives a .properties file error. Please check below errors.

enter image description here

It means. file uploaded, but internal data format is different.

+8
javascript jquery ajax ios
source share
1 answer

If you use JSONP now instead of text, the file will be loaded as javascript code, so if the content is invalid, javascript code will fail.

Surround data with global variable assignment or function call:

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

If _DATA_ is a JSON format, you do not need to surround it with quotation marks, otherwise you will need to use "_DATA_" because without quotation marks it will not be valid javascript syntax.

0
source share

All Articles