gpt4 book ai didi

javascript - 使用 Post 或 iframe 时,Internet Explorer 文件传输接收到的行重复

转载 作者:行者123 更新时间:2023-11-28 04:59:07 24 4
gpt4 key购买 nike

我需要将文件从计算机发送到嵌入式服务器,并出于测试目的将输出发送到 super 终端以查看收到的内容。如果我们在计算机上查看 F12 开发工具“网络”,正文通常是正确的,但有时第 3 行与第 2 行重复。在服务器端,接收到的行在整个传输中重复。出于测试目的,这是文件:

$A80000032W18%L6C3100D8
$A8000009EW18%LC31600D8
$A8000010AW18%LC31600D8
$A80000176W18%L532F00D8
$A800001E2W18%L22A200D8
$A800002BAW18%L393700D8
$A80000326W18%LE77600D8
$A80000392W18%L5E1900D8
$A800003FEW18%L488600D8
$A8000046AW18%LC77300D8
$A800004D6W18%L904500D8
$A80000542W18%L9F1800D8
$A800005AEW18%L76D400D8
$AEND

有什么建议吗?此传输适用于 Chrome 和 Firefox,但不适用于 IE 和 Edge。

最佳答案

        <!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>MS-Sedco Intersector Server</title>
<link href="toplevel.css" rel="stylesheet" type="text/css" />

</head>
<body>


<form name=connect >
<pre>




<input id="ConnType" type="submit" name=misce onclick="connecting()" value="Connect to Radar" size="2">
<input id="ConnStatus" type="hidden" name=Conn value="*DA;" size="2">
</pre>
</form>
<pre>
<input type="file" onchange='readText(this)' size="2">
</pre>

<pre>

<input type="button" onclick="program_boot()" value="Program" size="2">
</pre>

<pre>

<div id=BootStatus> </div> <div id=BootAddress> </div> <div id=b_test> </div>
</pre>


<form name=RTimeout>
<input type="hidden" name=misce value="RTimeout" size="2">
</form>

<form id="ie-fix" name="ie-fix" action="RadarBootLoader.htm" method="POST" target="booter-loader">
<input type="hidden" id="dataIE" name="" />
</form>
<iframe src="" id="boot-loader" name="boot-loader" style="display:none" width="100%" height="600"></iframe>

</body>

<script language="JavaScript">
//////////////////////////////////////////////////////////////////////////////////////
// Variables global to script
//////////////////////////////////////////////////////////////////////////////////////
var Temp_id;
var txt;
var etime;
var index;
var bootindex;
var output;
var address;
var done = 0;
var lastlineindex;
var prog_state = 0;
var sendout;
var reader = new FileReader();
var interval;

if ( document.getElementById("ConnStatus").value == 1 )
{
document.getElementById('BootStatus').innerHTML= " Radar Boot Connected";
}


function readText(that){

if(that.files && that.files[0]){
reader.onload = function (e) {
output=e.target.result;

//process text to show only lines with "@":
//output=output.split("\n").filter(/./.test, /\@/).join("\n");
output=output.split("\n")
document.getElementById('BootStatus').innerHTML= output;
sendout = output[0];
};//end onload()
reader.readAsText(that.files[0]);
}//end if html5 filelist support
}

function alertContents(httpRequest){
if (httpRequest.readyState == 4){
// everything is good, the response is received
if ((httpRequest.status == 200) || (httpRequest.status == 0)){
txt = httpRequest.responseText;
document.getElementById('BootStatus').innerHTML = httpRequest.responseText;
if ( (httpRequest.responseText).indexOf("Load Complete") > -1 )
{
prog_state = 0;
if ( done )
{
//done = 0;
//bootindex = 0;
clearInterval(etime);
document.getElementById('BootStatus').innerHTML = " Program Finished !!!";
}
else
{
//clearInterval(etime);
//etime = setTimeout( "timeout()", 1);
//document.getElementById('BootStatus').innerHTML = " Program Radar Flash Memory";
bootindex++;
sendout = output[bootindex];
if ( (output[bootindex]).indexOf("END") > -1)
{
done = 1;
}
else if ( (output[bootindex]).indexOf("$A") > -1)
{
address = "0x" + (output[bootindex]).substr(2, 8);
document.getElementById('BootAddress').innerHTML= " " + address;
}
//console.log(sendout);

if (window.XMLHttpRequest) {
send_with_ajax('RadarBootLoader.htm');
} else {
// Here is the IE fix test code
var iframe = document.getElementById("boot-loader");
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;

document.getElementById("dataIE").value = sendout;
document.getElementById("ie-fix").submit();
interval = setInterval(iframe_loaded, 2000);
}
}
}
//alert(bootindex);
//alert( "The response was: " + httpRequest.status + httpRequest.responseText);
//alert( (httpRequest.responseText).indexOf("bindex") );
//alert(document.getElementById("BootInd").value);
}else{
alert('There was a problem with the request. ' + httpRequest.status + httpRequest.responseText);
}
}
}

function iframe_loaded() {
var iframe = document.getElementById("boot-loader");
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
var httpRequest = {
readyState: 4,
status: 200,
responseText: "Load Complete"
};

console.log(iframeDoc.readyState);
if (iframeDoc.readyState == "complete") {
clearInterval(interval);
alertContents(httpRequest);
}
}

function send_with_ajax(url)
{
var http_request = false;

if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
//http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{ // IE
try {
http_request = new ActiveXObject("text/xml");
}
catch(e){
try
{
http_request = new ActiveXObject("text/xml");
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
}

if (!http_request)
{
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}

document.getElementById('b_test').innerHTML = bootindex;

if (window.XMLHttpRequest) {
http_request.onreadystatechange = function() { alertContents(http_request); };
http_request.open('POST', url, true);
http_request.setRequestHeader('Content-type', 'multipart/form-data');
http_request.setRequestHeader('Content-Encoding', "gzip");
http_request.send(sendout);
} else {
iframe_loaded();
}
}


function connecting()
{
document.getElementById('BootStatus').innerHTML= " Connecting Radar Boot Loader";
}

function program_boot()
{
document.getElementById('BootStatus').innerHTML= " Waiting Radar Echo";
etime = setTimeout( "timeout()", 10000);
prog_state = 1;
send_with_ajax('RadarBootLoader.htm');
}

function timeout()
{
if ( prog_state == 1 )
{
done = 0;
bootindex = 0;
alert("Can not Program Flash Memory !!");
document.getElementById('BootStatus').innerHTML= " ";
clearInterval(etime);
document.RTimeout.submit();
}
/*else
{
clearInterval(etime);
send_with_ajax('RadarBootLoader.htm');
document.getElementById('b_test').innerHTML = bootindex;
//etime = setTimeout( "timeout()", 10);
}*/
}

//////////////////////////////////////////////////////////////////////////////////////
// Infinite loop with delay
//////////////////////////////////////////////////////////////////////////////////////
function loop()
{
bootindex = 0;
}


//////////////////////////////////////////////////////////////////////////////////////
// Run
//////////////////////////////////////////////////////////////////////////////////////
window.onload=loop;


</script>
</html>

关于javascript - 使用 Post 或 iframe 时,Internet Explorer 文件传输接收到的行重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42307773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com