日期:2014-05-16 浏览次数:20390 次
function actionPost(ip,port) { var aform = document.createElement('form'); aform.method='post'; aform.action='/cgi-bin/post.cgi'; aform.enctype='application/x-www-form-urlencoded'; aform.target='postresult';//直接显示在一个iframe里是没问题的了 但是我想处理这个反馈 var obj=document.createElement('input'); obj.type='hidden'; obj.name='hostIP'; obj.value=ip; aform.appendChild(obj); obj=document.createElement('input'); obj.type='hidden'; obj.name='hostPort'; obj.value=port; aform.appendChild(obj); document.body.appendChild(aform); aform.submit(); return false; }
<script type="text/javascript"> var AjaxUtil = { /** * 提交请求 */ request:function(url,params,callback) { var xhr = this.createXhrObject(); xhr.onreadystatechange = function() { if(xhr.readyState !== 4) { return; } if(xhr.status === 200) { callback(xhr.responseText) } else { throw new Error('请求失败:' + xhr.responseText); } }; xhr.open('POST',url + "?" + params,true); xhr.send(null); } ,createXhrObject:function() { var methods = [ function(){ return new XMLHttpRequest();} ,function(){ return new ActiveXObject('Msxml2.XMLHTTP');} ,function(){ return new ActiveXObject('Microsoft.XMLHTTP');} ]; for(var i=0,len=methods.length; i<len; i++) { try { methods[i](); } catch (e) { continue; } this.createXhrObject = methods[i]; return methods[i](); } throw new Error("创建XHR对象失败"); } }; </script> <script type="text/javascript"> function callback(e) { // 这里就是想要单词 alert(e) } var ip = '192.168.172.108'; var port = 1822; // 请求 AjaxUtil.request('/cgi-bin/post.cgi','ip='+ip+'&port=' + port,callback); </script>