Controller.Json()在JsonResult中追加垃圾符号(如问号) [英] Controller.Json() is appending junk symbols (like question mark) in JsonResult
本文介绍了Controller.Json()在JsonResult中追加垃圾符号(如问号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Controller.Json()。但是在JsonResult中,我的数据附加了垃圾数据。它过去在VS2013中正常工作,但在VS2015中给出了这样的问题。
输出如下:
[{ TotalRowCount: 6 , TotalPageCount: 1 , GridData:[{ LocationId: 55 , Location_Name: asd, 国家/地区: null , 状态: null , 城市: null , Pin_Code: null , Created_By: 27 , Updated_By: 27 , Created_Date: null , Updated_Date : \ / Date(1438338668570)\ /, Is_Active: false , SectionCount: 1 , Section_Mst_List: null , FTPServer: null , FTPUserName: null , FTPPassword : null , MG_LoginId: null , MG_Password: null , MG_HardwareId: null }]]
因此,它在javascript中提供了解析错误(语法错误:意外的令牌)
CS代码:
[HttpGet]
public JsonResult GetLocationMaster(Location_Mst location, int 行, int 页面, string sidx, string sord)
{
GridDataResult gridDataResult = repo.GetLocationMaster(location,rows,page,sidx,sord);
List< GridDataResult> lst = new List< GridDataResult>();
lst.Add(gridDataResult);
JsonResult jr = Json(lst.ToArray(),JsonRequestBehavior.AllowGet);
return jr;
}
JavaScript AJAX电话:
var url = ' @ Url .Action(GetLocationMaster,Location)';
$ .ajax({
url:url,
type:' GET',
dataType:' json',
cache: false ,
contentType:' application / json; charset = utf-8',
成功: function (data){}
})。fail(
function (xhr,textStatus,err){
alert(err);
});
我也试过了一个小提琴,但没用。
解决方案
.ajax({
url:url,
类型:' GET',
dataType: ' json',
cache: false ,
conten tType:' application / json; charset = utf-8',
成功: function (data){}
})。失败(
function (xhr,textStatus ,错误){
alert(err);
});
我也尝试过小提琴,但没用。
< blockquote>调试并检查垃圾数据是否附加在cs代码上或附加在响应之间或客户端之间
以便我们可以相应地跟踪它。
I am using Controller.Json(). But in the JsonResult, my data is appended with junk data. It used to work properly in VS2013, but is giving such issue in VS2015.
Output something like this:
[{"TotalRowCount":6,"TotalPageCount":1,"GridData":[{"LocationId":55,"Location_Name":"asd","Country":null,"State":null,"City":null,"Pin_Code":null,"Created_By":27,"Updated_By":27,"Created_Date":null,"Updated_Date":"\/Date(1438338668570)\/","Is_Active":false,"SectionCount":1,"Section_Mst_List":null,"FTPServer":null,"FTPUserName":null,"FTPPassword":null,"MG_LoginId":null,"MG_Password":null,"MG_HardwareId":null}]]���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
Hence, it gives parse error in javascript (Syntax error: Unexpected token)
CS code:
[HttpGet]
public JsonResult GetLocationMaster(Location_Mst location, int rows, int page, string sidx, string sord)
{
GridDataResult gridDataResult = repo.GetLocationMaster(location, rows, page, sidx, sord);
List<GridDataResult> lst = new List<GridDataResult>();
lst.Add(gridDataResult);
JsonResult jr = Json(lst.ToArray(), JsonRequestBehavior.AllowGet);
return jr;
}
JavaScript AJAX call:
var url = '@Url.Action("GetLocationMaster", "Location")';
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
cache: false,
contentType: 'application/json;charset=utf-8',
success: function (data) {}
}).fail(
function (xhr, textStatus, err) {
alert(err);
});
I also tried a Fiddle trace, but no use.
解决方案
.ajax({ url: url, type: 'GET', dataType: 'json', cache: false, contentType: 'application/json;charset=utf-8', success: function (data) {} }).fail( function (xhr, textStatus, err) { alert(err); });
I also tried a Fiddle trace, but no use.
debug and check if junk data is appended on cs code or its appending in between the response or at client side
so that we can trace it accordingly.
这篇关于Controller.Json()在JsonResult中追加垃圾符号(如问号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文