angular.js $http.get how to force UTF-8 encoding

前端 未结 2 1850
鱼传尺愫
鱼传尺愫 2020-12-17 01:06

I\'ve to read JSON file encoded with utf-8 charset
I use this syntax:

$http.get(\'resources/negozi.json\',
    {header : {\'Content-Type\' : \'applicatio         


        
相关标签:
2条回答
  • 2020-12-17 01:36

    If you are using php as server-side programming language you can try to set the internal encoding to utf-8 with mb_internal_encoding("utf-8").

    0 讨论(0)
  • 2020-12-17 01:41

    It looks like you might need to set an Accept header. The contentType header applies to the stuff you're sending;

    Accept: application/json;charset=UTF-8
    Accept-Charset: UTF-8
    

    so;

    $.ajax({
       type:"GET",
       url:"resources/negozi.json",
       headers: {
           "Accept": "application/json;charset=utf-8",
           "Accept-Charset":"charset=utf-8"
       },
       dataType:"json"
    });      
    
    0 讨论(0)
提交回复
热议问题