First, let's look at the background of the problem: website A uses iframe to reference A static html of website B. Part of html of website B needs to be obtained through website C. Here I need to implement Part B to C. Technical Architecture used: struts2, spring, ibatis, and jquery. Try to introduce js remotely. For example, http ://
First, let's look at the background of the problem:
Website A uses the iframe method to reference A static html of website B. Part of the html content of website B needs to be obtained through website C. Here I need to implement Part B to C.
Technical Architecture used: struts2, spring, ibatis, and jquery.
Try to introduce js remotely. For example, http://www.c.com/.mongomongo.js.execute the ajaxrequest in C.
$. Ajax ({
Url: '/showAjax. action ',
Data: 'lotteryid = '+ lotteryId,
Type: 'post ',
DataType: 'json ',
Success: function (json ){
...,
// Alert (json );
Return *;
}
});
Later I found myself making a mistake. In jquery ajax success, return cannot be executed.
The following is a summary of your implementation (web Proxy ):
1. web-side proxy, that is, the cross-origin access requests generated by the user to access website B are submitted to the specified page of website B, which replaces the user page for interaction, return the appropriate results.
2. Cross-origin security restrictions refer to cross-origin security restrictions on the browser side. The server side does not have cross-origin security restrictions. Therefore, the local server side uses the httpclient-like method to complete cross-origin access,
Then, use AJAX on the browser side to obtain the url corresponding to the "cross-origin access" on the local server side. This is also possible for indirect cross-origin access. However, it is clear that the development volume is large, but the limit is also minimal.
Paste the following code:
1. B website front-end:
$. Ajax ({
Url: '/showCpAjax. action ',
Data: 'lotteryid = '+ lotteryId,
Type: 'post ',
DataType: 'json ',
Success: function (json ){
Var periodStr = json. period;
Var timeStr = json. endTime;
// Ignore some code here
}
});
2. ajax submits the request to the background of website B:
Public String showCpIndex (){
String url = "http://www.c.com/?##.do"; // request the csite
HttpClient client = new HttpClient ();
GetMethod get = new GetMethod (url );
Try {
Int statusCode = client.exe cuteMethod (get );
If (statusCode = HttpStatus. SC _ OK ){
String response = get. getResponseBodyAsString ();
ServletActionContext. getResponse (). setCharacterEncoding ("UTF-8 ");
// Respose is the data returned by the request to the csite.
} Else {
//***
}
} Catch (Exception e ){
E. printStackTrace ();
}
Return SUCCESS;
}
3. The csite is just a common struts2action method, and the returned view is a common JSP. All content in jsp is returned to B as a reponse.