WCF would have been used, but the service would need to be called in multiple ways (background + front-end Ajax), and the final situation was that I judged it in every WCF service ↓
#regionResolves a parameter that was not received in Ajax ...if(Jsonparames = =NULL&& httpcontext.current.request.querystring["Parameters"] !=NULL) Jsonparames= httpcontext.current.request.querystring["Parameters"]; Else if(Jsonparames = =NULL&& httpcontext.current.request.querystring["Parameters"] ==NULL) returnJson. Instance.tojson ("{\ "ret\": \ "0\", \ "msg\": \ "parameter is empty. \"}"); #endregion
But there is a length limit to using QueryString to transmit data in Ajax.
And someone said they could use a form to resolve the submission.
<form id='Form0'Method='POST'action='http://localhost:22377/api/Article_/Article_Update/'onsubmit ="set_v ()"><input id='Id_v'Type='Hidden'Value='Value_default'Name='Jsonparames'/><input type="Submit"Value="XXX" class=""/></form>
However, after the submission is finished, the page will be directly redirected to the page where action is directed ...
Finally, decide to publish a Web API, and then use Ajax to solve
<form id= "Form1" > <div>ID:<input type= "text" id= "id_id"/> <br/> <input type= "button" value= "POST" id= "getpers Ons "/> </div> <div id=" ret "> </div> </form> <script type=" text/j Avascript ">functionSet_v () {alert (' Set value! '); varv = ' too long data. '; document.getElementById ("Id_v"). Value =v; Alert (document.getElementById ("Id_v"). Val ()); }$ (' #getPersons '). Click (function() {document.getElementById ("ret"). InnerHTML = ';//clear last query content ... varID = $ ("#id_ID"). Val ();$.ajax ({type:' POST ',URL: ' Http://localhost:22377/api/Article_/Article_Update ',//? jsonparames= ' + Jsonparames, //dataType: ' JSONP ',//If the line does not annotate the requested ' type ' is get, (even if the first line specifies the type: ' POST ') //contentType: "Application/json; Charset=utf-8; ",//This line does not comment that cross-domain calls are not allowed!!!data: {"Jsonparames": ' {"id": "0"} '//jsonparames corresponds to the parameter name in the Web API; },Successfunction(_data) {alert (_data); varinfo = eval (' (' + _data + ') '); //alert (data); varList = eval (' (' + info.list + ') '); varFragment =document.createdocumentfragment (); $.each (list,function(i, field_list) {$.each (field_list,function(i, field) {varItem = document.createelement ("li"); Item.appendchild (document.createTextNode (' [' + i + '] ' + ' ... ' +field)); Fragment.appendchild (item); //Alert (i + "... is ..." + field); }) }) $("#ret"). append (fragment); }, Error:function () { } }); }); </script>
the Web API;
[HttpPost, HttpGet] Public stringArticle_update ([Frombody]stringjsonparames) { if(string. IsNullOrEmpty (jsonparames) | | Jsonparames.tolower () = ="Jsonparames") {Jsonparames= system.web.httpcontext.current.request.form["Jsonparames"]; } return "xx";}
Using AJAX to invoke the Web API, the URL is too long to solve the problem;