Javascript 如何让mvc动作触发jQueryAjax转换器?
如何使mvc控制器操作命中ajax转换器。我可以修改响应以触发此消息吗Javascript 如何让mvc动作触发jQueryAjax转换器?,javascript,jquery,ajax,model-view-controller,converter,Javascript,Jquery,Ajax,Model View Controller,Converter,如何使mvc控制器操作命中ajax转换器。我可以修改响应以触发此消息吗 $.ajaxSetup({ converters: { "mytype1 mytype2": function (result) { //do stuff return newresult; } } }); 我尝试过如下更改JsonResult的内容类型和内容编码: result.ContentType = "mytype1";
$.ajaxSetup({
converters: {
"mytype1 mytype2": function (result) {
//do stuff
return newresult;
}
}
});
我尝试过如下更改JsonResult的内容类型和内容编码:
result.ContentType = "mytype1";
..
response.AppendHeader("Content-Encoding", "mytype1");
但毫无疑问
编辑:
我真正想要的是更改我的mvc操作的返回类型,并添加一个ajax转换器(“mytype1 json”),并且仍然拥有所有现有的$.ajax调用,这些调用期望json工作我假设您正在从服务器返回
json
,您可以在转换器中提取json并返回您自己的类型
$.ajaxSetup({
converters: {
"json mytype2": function (result) {
//do stuff
return newresult;
}
}
});
然后您可以进行普通的ajax调用
$.ajax({
url:'',
type:'',
dataType:'json mytype2',
success:function(data){
// data will be newresult
}
});
您不必从服务器端显式调用转换器从服务器xml返回什么?json?到目前为止我只试过JsonResult..是的。我注意到了。我希望明确地调用转换器。我将编辑我的问题以反映我真正想要的。