In the display page, using AJAX to post the value of the value data is in JSON format. Received in the controller, but only partial values were received. There is a url,url in the data that contains the special symbol &, and the received value is to this symbol, the following is not. For example, data in the source code is the value I want.
Reply content:
In the display page, using AJAX to post the value of the value data is in JSON format. Received in the controller, but only partial values were received. There is a url,url in the data that contains the special symbol &, and the received value is to this symbol, the following is not. For example, data in the source code is the value I want.
Depends on the type you pass to data:
- In the case of an object, jquery automatically adds the encodeuricomponent,& symbol when the AJAX request is sent, is encoded as%26, and is not automatically truncated by formdata
- If data is a string, jquery automatically places the string in Formdata and sends it to the server intact, because Formdata is truncated by &, so the string is automatically truncated AT & without encodeURIComponent.
Before submitting, URL encode you pass this URL
The value corresponding to data is encapsulated with Json.stringify ({}).
For example:
$(".a_post").on("click",function(event){ event.preventDefault();//使a自带的方法失效 $.ajax({ type: "POST", url: "url地址", contentType:"application/json", data: JSON.stringify({param1:"param1",param2:"param2",url:"http://xxxx?a=a&b=b&c=c",param3:"param3"}),//参数列表 dataType:"json", success: function(result){ //请求正确之后的操作 }, error: function(result){ //请求失败之后的操作 } });});
View the request parameters as follows:
With this json.stringify ({}) encapsulated, is the Ajax transmission of the time of the problem, with the data: ' Data= ' +data, so that the value is a problem, but with data:{data:data}, you can, is why?