1、编辑用户时,报错。后面有跟解决方案。
解决方案1:
2、导致出错的原因是这样的,这里的功能是请求服务端的html页面,渲染后显示编辑页面。
关键点是默认参数那儿
路径:aspnet-coresrcMyABP.Web.Mvcwwwrootlibabp-web-resourcesAbpFrameworkscriptslibsabp.jquery.js
defaultOpts: { dataType: 'json', type: 'POST', contentType: 'application/json', headers: { 'X-Requested-With': 'XMLHttpRequest' } },
默认请求的json格式的数据,使用的时候,只覆盖了 contentType 这个参数,dataType 这个参数没有覆盖,所以就出错了,返回的html肯定是不能转换成json。
abp.ajax({ url: abp.appPath + 'Users/EditUserModal?userId=' + userId, type: 'POST', contentType: 'application/html', success: function (content) { $('#UserEditModal div.modal-content').html(content); }, error: function (e) { } });
有两种修改方案:
1、传值的时候,把dataType这个参数传过去。
2、在源码里面,把dataType设置为null,让jQuery自己判断返回的数据类型。
源码截图:
这里只覆盖了一个参数 dataType
abp.ajax.defaultOpts 这个是请求数据时,默认的配置参数。
默认的配置参数一览: