A recent project used JQuery to call the json data returned by Struts2 Action. Because cross-origin operations are involved, the getJson method that is compatible with cross-origin operations has been selected, however, in actual application, it is found that jquery, which is also purchased by the front end, can call the background Action class successfully... syntaxHighlighter. a
A recent project used JQuery to call the json data returned by Struts2 Action. Because cross-origin operations are involved, the getJson method that is compatible with cross-origin operations has been selected, however, in actual applications, it is found that jquery, which is also purchased by the front end, can call the background Action class successfully, but it is always unable to call the callback function!
After constant search, the cause is finally determined. To successfully call the callback function in a cross-origin call, the server must explicitly know the callback function address. Therefore, there are two necessary elements:
1. callback = ?, This name can be set by yourself. It is not necessarily called, but it must be
2. The struts2 configuration file must contain Jsoncallback
The name of the callback parameter is the same as that passed by the front-end.
The following shows the code snippet I used:
Front-end page: www.2cto.com
$. GetJSON ('HTTP: // xxxxxxx.xhtml? '+ $ (' # RegForm '). serialize () + "& jsoncallback =? ", Function (data ){
Alert (data );
});
Back-end struts-json.xml calibration return value part, note to be included in the result segment
Jsoncallback
Author: mcbeath