that is my code , and i am wonder that why my web service in .net 4.0 always return data as a xml format instead of json .
Webservice :
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public FileModel HelloWorld()
{
FileModel model= new FileModel();
model.Name = "peyman";
return model;
}
jQuery :
I get files list in drop event with: var files = event.originalEvent.dataTransfer.files;
and then call upload(files);
function upload(files) {
var data = new FormData();
jQuery.each(files, function(i, file) {
data.append('file-' + i, file);
});
$.ajax({
type : "POST",
url : parameters.Url,
contentType : false,
processData : false,
data : data,
dataType : "json",
success : function(msg) {
alert(msg);
},
error : function() {
alert("err");
}
});
}
Also i tried some thing like :
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
Context.Response.ContentType = "application/json";
- Adding
"application/json"
or"text/json"
to response header
but response content-type is always "text/xml; charset=utf-8"