你可以這樣做;我測試了它,它不存在這樣的問題:
在瀏覽器(JQuery的/ JavaScript的):
function newModule() {
var path = $("#path").val(); // Whatever value you want to be sent.
$.ajax({
url: "{% url 'modules' %}", // Handler as defined in Django URLs.
type: "POST", // Method.
dataType: "json", // Format as JSON (Default).
data: {
path: path, // Dictionary key (JSON).
csrfmiddlewaretoken:
'{{ csrf_token }}' // Unique key.
},
success: function (json) {
// On success do this.
},
error: function (xhr, errmsg, err) {
// On failure do this.
}
});
在服務器引擎(蟒蛇):
def handle(request):
# Post request containing the key.
if request.method == 'POST' and 'path' in request.POST.keys():
# Retrieving the value.
current_title = request.POST['path']
# You can also do |ttl = current_title.encode('utf-8')| to make sure.
# ...
這似乎是一個字符串編碼問題,請閱讀:[每個軟件開發人員必須知道的關於Unicode和字符集的絕對最低限度](http://www.joelonsoftware.com/articles/Unicode.html) – bastelflp