contentTypeআপনি যে ডেটা প্রেরণ করছেন তা application/json; charset=utf-8হ'ল সাধারণ, যেমনটি application/x-www-form-urlencoded; charset=UTF-8ডিফল্ট।
dataTypeকি আপনি সার্ভার থেকে ফিরে পাবার আশা করছেন যারা json, html, text, ইত্যাদি jQuery এর এই ব্যবহার জিনিসটা সাফল্য ফাংশনের প্যারামিটার পূরণ করতে কিভাবে হবে।
আপনি যদি এমন কিছু পোস্ট করেন:
{"name":"John Doe"}
এবং ফিরে প্রত্যাশা:
{"success":true}
তারপরে আপনার উচিত:
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
},
});
আপনি যদি নিম্নলিখিতগুলি আশা করে থাকেন:
<div>SUCCESS!!!</div>
তারপরে আপনার করা উচিত:
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
},
});
আরও একটি - আপনি যদি পোস্ট করতে চান:
name=John&age=34
তারপরে stringifyডেটা করবেন না এবং করুন:
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
},
});