How to change ajax-charset?

前端 未结 4 2009
鱼传尺愫
鱼传尺愫 2020-12-03 11:09

How can I change the default encoding used by $.post()?

The arguments are encoded with UTF-8. How can I encode it with ISO 8859-1?

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 11:47

    By giving the content type explicitly during ajax call as below may allow you to override the default content type.

    $.ajax({
            data: parameters,
            type: "POST",
            url: ajax_url,
            timeout: 20000,
            contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
            dataType: 'json',
            success: callback
    });
    

    You would also have to specify the charset on the server.

    Ex: for php

    
    

    I hope this may help you.

提交回复
热议问题