Home > Article > Web Front-end > EasyUI's datagrid cross-domain call implementation code in ASP.NET MVC_jquery
In recent projects, I need to call data from other projects across domains. Other projects also use EasyUI's datagrid component. I initially thought that it would be enough to directly define the url attribute of the datagrid as the url address of other projects. However, after testing, I found that json data was indeed returned. However, the json data prompts an "invalid label" error. I searched online for a solution to the error. Refer to the method "JavaScript Processing Json Invalid Label Error Solution" and used the loadData method of the datagrid to load and convert the json. It still prompts the above error. I feel that the reason is not there. Format issue.
I searched for the article "JavaScript cross-domain access problem solution" and found out that it is because easyUI uses JQuery's asynchronous method to load data and should follow JQuery's cross-domain access rules. , that is, jsoncallback= needs to be added to the URL mentioned in the above article? Callback function parameters, and the format of the returned json must be modified to: callback function name (json data), and now the data returned is only data in json format without a callback function name, which naturally prompts a format error, so I modified the ASP.NET MVC auto The defined JsonResult class, for details on how to write a custom JsonResult class, see: Customizing ASP.NET MVC JsonResult serialization results,
The code is as follows: