contentTypegönderdiğiniz veri türüdür, bu yüzden application/json; charset=utf-8yaygın olanıdır, application/x-www-form-urlencoded; charset=UTF-8bu varsayılan değerdir.
dataTypesunucudan geri bekliyorsanız ne: json, html, textvb jQuery başarı işlevin parametresi doldurmak anlamaya bunu kullanır.
Şöyle bir şey gönderiyorsanız:
{"name":"John Doe"}
ve tekrar beklemek:
{"success":true}
O zaman sahip olmalısınız:
var data = {"name":"John Doe"}
$.ajax({
dataType : "json",
contentType: "application/json; charset=utf-8",
data : JSON.stringify(data),
success : function(result) {
alert(result.success); // result is an object which is created from the returned JSON
},
});
Aşağıdakileri bekliyorsanız:
<div>SUCCESS!!!</div>
O zaman yapmanız gerekenler:
var data = {"name":"John Doe"}
$.ajax({
dataType : "html",
contentType: "application/json; charset=utf-8",
data : JSON.stringify(data),
success : function(result) {
jQuery("#someContainer").html(result); // result is the HTML text
},
});
Bir tane daha - göndermek istiyorsanız:
name=John&age=34
Sonra stringifyverileri yapmayın ve şunları yapın:
var data = {"name":"John", "age": 34}
$.ajax({
dataType : "html",
contentType: "application/x-www-form-urlencoded; charset=UTF-8", // this is the default value, so it's optional
data : data,
success : function(result) {
jQuery("#someContainer").html(result); // result is the HTML text
},
});