[英]Cross Domain post Javascript
所以我正在嘗試制作一個網頁,通過客戶端啟動本地應用程序。
我能想到的簡單解決方案就是將數據發布或獲取到我想要使用的端口; 說端口3000.不幸的是我遇到了一個錯誤: XMLHttpRequest cannot load %3127.0.0.1:3000. Cross origin requests are only supported for HTTP.
XMLHttpRequest cannot load %3127.0.0.1:3000. Cross origin requests are only supported for HTTP.
我的問題:有沒有辦法使用XMLHttpRequest()將數據發布或獲取到127.0.0.1:3000?
抱歉格式化的混亂,我玩了很長時間,我無法正確縮進D:
function Post_Command(Command_String){
if(typeof(Command_String) != "string"){
console.log(
"Invalid Call:\Post_Command(\n\t"+Command_String+":"+typeof(Command_String)+"\n)"
);
} else {
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
console.log(xmlhttp.responseText);
}
}
xmlhttp.open(
"POST",
"127.0.0.1:3000",
true
);
xmlhttp.send(Command_String);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.