I am a front-end novice and encountered the problem of cross-domain access. I am here to ask for advice. The following is a jquery script automatically generated by postman. It is available in postman, but after it is placed in a certain html, cross-domain access will appear when accessing. The problem of domain access denial is shown in Figure 1 below.
var form = new FormData();
form.append("data", "[{\"serviceUrl\" : \"/bank_auth\",\"apiKey\" : \"3FE8D08DB99D326D\",\"areacode\":\"000000\"} ]");
var settings = {
"async": true,
"crossDomain": true,
"url": "http://xxx.xxx.com:58080/gateway-web-1.8.0/getTicket",
"method": "POST",
"headers": {
"cache-control": "no-cache",
"postman-token": "932148f8-c97b-631c-5a3e-8411a622abd9"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(settings).done(function (response) {
console.log(response);
});
图1
The following is the access code using jsonp that I found online. I can successfully access the getTicket interface, but
How do I pass the data shown in the above code to the server? , please advise
This question should be very simple for anyone with some front-end basics, but a novice like me doesn’t know how to do it!
<script>
function submitForm(){
var form = new FormData();
form.append(
"data",
"[{\"serviceUrl\" : \"/bank_auth\",\"apiKey\" : \"3FE8D08DB99D326D\",\"areacode\":\"000000\"} ]");
var url = 'http://xxx.xxxxx.com:58080/gateway-web-1.8.0/getTicket';
$.ajax(url, {
data: form,
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
if(data && data.resultcode == '200'){
console.log(data.result.today);
}
}//success: function(data)
}); //$.ajax(url, {
}//function submitForm()
function clearForm(){
$('#ff').form('clear');
}
</script>
The following is the RESTFUL interface of my server:
@RequestMapping(value = "/getTicket", method = { RequestMethod.POST, RequestMethod.GET })
public String executeTicket(HttpServletRequest request, HttpServletResponse response, String data)
黄舟2017-05-19 10:48:03
jsonp can only get, you can consider using CORS for cross domain
function submitForm() {
var url = 'http://xxx.xxxxx.com:58080/gateway-web-1.8.0/getTicket';
$.ajax({
url: url,
method: 'post',
contentType:'application/json',
data: JSON.stringify({
serviceUrl: 'bank_auth',
apiKey: '3FE8D08DB99D326D',
areacode: '000000'
}),
dataType: 'json',
crossDomain: true,
success: function(data) {
if (data && data.resultcode == '200') {
console.log(data.result.today);
}
} //success: function(data)
}); //$.ajax(url, {
} //function submitForm()
function clearForm() {
$('#ff').form('clear');
}