Javascript - encodeURI () saving different results in different browsers

I use encodeURI () to encode the php request url, it works fine in Firefox and Chrome, but it is not in IE / Edge.

Actual URL: http://localhost/get.php?id=e_e2&title=e2&desc=just a note&stime=6/12/2015, 1:00:00 AM&etime=15/12/2015, 1:00:00 PM

What Firefox returns (works): http://localhost/get.php?id=e_HO%20Event%201&title=HO%20Event%201&desc=This%20is%20just%20a%20test%20event%20of%20this%20handover%20only&stime=6/12/2015,%201:00:00%20AM&etime=10/12/2015,%201:00:00%20PM

What returns IE (php code break): http://localhost/get.php?id=e_HO%20Event%201&title=HO%20Event%201&desc=This%20is%20just%20a%20test%20event%20of%20this%20handover%20only&stime=%E2%80%8E6%E2%80%8E/%E2%80%8E12%E2%80%8E/%E2%80%8E2015%E2%80%8E%20%E2%80%8E1%E2%80%8E:%E2%80%8E00%E2%80%8E:%E2%80%8E00%E2%80%8E%20%E2%80%8EAM&etime=%E2%80%8E10%E2%80%8E/%E2%80%8E12%E2%80%8E/%E2%80%8E2015%E2%80%8E%20%E2%80%8E1%E2%80%8E:%E2%80%8E00%E2%80%8E:%E2%80%8E00%E2%80%8E%20%E2%80%8EPM

I tried to decode what IE returns, but it caused me a lot of problems !, so there are alternatives to encodeURI () ?, FF seems to work even if I don’t encode the URL where IE works if I copy FF encoded url to it!


update: sample code link

I think this has something to do with toLocaleString ()


Final update:

, " IE!". php script ,

function FixLocaleDateString(localeDate) {
    var newStr = "";
    for (var i = 0; i < localeDate.length; i++) {
        var code = localeDate.charCodeAt(i);
            if (code != 44 && code != 8206 ) {
                newStr += localeDate.charAt(i);
            }
    }
        return newStr;
}

: ToLocaleDateString() IE11

+4
3

encodeURI (, , encodeURI, encodeURIComponent, ).

, - U+200E "LEFT-TO-RIGHT MARK" ( , ), %E2%80%8E.

, / , , .

+3

params URL . , encodeURIComponent().

var params = {
  'id': 'e_'.concat(event.title.toString()),
  'title': event.title.toString(),
  'desc': event.description.toString(),
  'stime': stime.toString(),
  'etime': etime.toString()
};

var chunks = [];
for (var property in params) {
  if (params.hasOwnProperty(property)) {
    chunks.push(property.concat('=', encodeURIComponent(params[property])));
  }
}
var href = 'http://localhost/get.php?'.concat(chunks.join('&'));

console.log(href);
0
source

Source: https://habr.com/ru/post/1619690/


All Articles