0 Answer
I have tried all the above methods, and they are guaranteed. net::ERR_CONNECTION_REFUSED
using ajax backend sends the request format: < br / > < br / > $. Ajax({< br / > common attributes: < br / > url: Requested server url
async:(Default: true) By default, all requests are asynchronous. If you want to send a synchronization request, set this option to false.
data: data sent to the server, either as a key-value pair or as a js object
type:(Default: "GET") request method(" POST "or" GET "), the default is "GET" < br / > dataType: The type of data expected to be returned, The value can be xml, html, script, json, text, _defaul, etc.
success:function(result){
Callback function after successful request
result indicates the callback value
},
error:function(){
This function is called when a request fails and an exception occurs on the server.
}
Note: The above properties are case sensitive.
The most powerful aspect of this method is that it can give friendly hints when handling server exceptions.
});
This answer quotes ChatGPT
In JavaScript, you can use the XMLHttpRequest object or the Fetch API to send HTTP requests and fetch remote resources.
Here is sample code for sending a POST request using the XMLHttpRequest object:
const xhr = new XMLHttpRequest();
const url = "http://ip:端口/sms/smsapi/getTpllist";
const apikey = "26743791-298c-4d6e-80de-31af53382697";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
const response = xhr.responseText;
console.log(response); // 处理获取到的响应数据
}
};
const data = {
apikey: apikey,
};
xhr.send(JSON.stringify(data));
Example code for sending a POST request using the Fetch API:
const url = "http://ip:端口/sms/smsapi/getTpllist";
const apikey = "26743791-298c-4d6e-80de-31af53382697";
const options = {
method: "POST",
headers: {
"Content-Type": "application/json;charset=UTF-8",
},
body: JSON.stringify({ apikey }),
};
fetch(url, options)
.then((response) => response.text())
.then((data) => console.log(data))
.catch((error) => console.log(error));
Note that cross-domain access to external resources exists in JavaScript. If your website and interface service are not in the same domain name, you need to configure cross-domain access on the server side. Note If you access HTTPS websites, pay attention to the SSL certificate.
The little girl referred to bing and GPT part of the content write :
Access to the Internet http request, you can use the JavaScript XMLHttpRequest object. The XMLHttpRequest object helps us make an asynchronous HTTP request without blocking other operations on the current page.
Here is an example of implementing an extranet http request using XMLHttpRequest:
let xhr = new XMLHttpRequest(); //创建一个XMLHttpRequest对象
xhr.open('GET', 'http://www.example.com/', true); //打开一个连接,true表示异步请求
xhr.send(null); //向服务器发送请求
xhr.onreadystatechange = function(){ //监听readystatechange事件
if(xhr.readyState == 4 && xhr.status == 200){ //判断状态码是否为200,200表示请求成功
let responseText = xhr.responseText; //获取服务器返回的数据
console.log(responseText); //将数据打印在控制台上
}
}
The answer is not easy, so take it.
这家伙很懒,什么都没留下...