<summary>///Login/// </summary>/ <param name= "value" ></param> // <returns></returns> public Jsonresult Login () { list<factory> userlist = new list< Factory> { new factory{factory_name= "Zzl", factory_code= "[email protected]"},
Return JSON (JSON); }
Return JSON (JSON, jsonrequestbehavior.allowget);//Foreground Ajax if it's a get, use this sentence
When to use GET request, when we enter the URL directly in the browser, is actually a GET request
If we enter/home/testlist this URL directly, it will prompt us to download this JSON-formatted document
$ (function () { $ ("#Get"). Click (function () { $.ajax ({ type: "POST", contentType: "Application/json" , URL: "Test/login", dataType: ' json ', success:function (result) { var msg = "<table border=1px> <tr><td>Name</td><td>Code</td></tr> "; for (var i = 0, length = result.rows.length; i < length;i++) { //alert (result.rows[i]["Factory_name"]); msg + = "<tr><td>" + result.rows[i]["factory_name"] + "</td><td>" + result.rows[i]["Factory_ CODE "] +" </td></tr> "; } msg + = "</table>"; $ ("#msg2"). HTML (msg);}); } );
Working with JSON in MVC view