在window.open()中执行POST

时间:2014-01-22 19:41:30

标签: javascript jquery http-post

我正在尝试打开一个弹出窗口,我想在打开时使用post方法发送数据。  任何人都可以帮助我。

我正在"Uncaught syntax error. Unexpected token }"

function MapIt(){    
    var ListIds = selected_Listings.join();
    if (navigator.appName == "Microsoft Internet Explorer") {
        var opts = "screenX=0,screenY=0,width=" + screen.width + ",height=" + screen.height;
    } else {
        var opts = "outerWidth=" + screen.availWidth + ",outerHeight=" + screen.availHeight + ",screenX=0,screenY=0";
    }    
    var urlStr = "http://www.dev.theabc.com/bingmaps/Map  ";     
    $('<form action=' + urlStr + ' ' + ' target="submission" onsubmit="window.open("", "Map",' + opts + ' "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");return true;" method="post"><input type="hidden" name="listid" value="' + ListIds + '"></form>').submit();
}

2 个答案:

答案 0 :(得分:1)

实际上......你的语法在表单中是错误的 看起来应该是这样的

$('<form action="'+urlStr+' target="submission" onsubmit="window.open(\'http://www.google.com\',\'Map\',\''+opts+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no\');return true;" method="post"><input type="hidden" value="'+ListIds+'"></form>').submit();

你必须逃避“在弦内......哦,在选择之后失去了昏迷......

<html>
<head>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
  <script type='text/javascript'>
  $(function(){
   MapIt = function() {
     ListIds = '1234';//selected_Listings.join();
     if (navigator.appName == "Microsoft Internet Explorer") {
       var opts = "screenX=0,screenY=0,width=" + screen.width + ",height=" + screen.height;
    } else {
      var opts = "outerWidth=" + screen.availWidth + ",outerHeight=" + screen.availHeight + ",screenX=0,screenY=0";
    }

   var urlStr = "http://wwwd.dev.theabc.com/bingmaps/Map";
   $('<form action="'+urlStr+' target="submission" onsubmit="window.open(\'http://www.google.com\',\'Map\',\''+opts+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no\');return true;" method="post"><input type="hidden" value="'+ListIds+'"></form>').submit();
}
});
</script>
</head>
<body>
 <button id="run" onclick="MapIt()">run</button>
</body>
</html>

答案 1 :(得分:1)

知道你真的不想要一个帖子。

<html>
 <head>
   <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
   <script type='text/javascript'>
   $(function(){
     MapIt = function() {
       ListIds = '1234';//selected_Listings.join();
       if (navigator.appName == "Microsoft Internet Explorer") {
         var opts = "screenX=0,screenY=0,width=" + screen.width + ",height=" + screen.height;
       } else {
         var opts = "outerWidth=" + screen.availWidth + ",outerHeight=" + screen.availHeight + ",screenX=0,screenY=0";
       }
       $('#myHidden').val(ListIds);
       window.open('opener.html','Map', opts+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no');

     }
    });
   </script>
 </head>
 <body>
  <button id="run" onclick="MapIt()">run</button>
  <input type="hidden" id="myHidden">
 </body>
</html>

然后在你的opener.html中

<html>
 <head>
   <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
   <script type='text/javascript'>
     $(function(){
        var listIds = window.opener.document.getElementById('myHidden').value;
    $('#valuesRead').text(listIds);
      });
   </script>
 </head>
 <body>
   <span id="valuesRead"></span>
 </body>
</html>

请注意如果您在本地运行,则在某些浏览器(Chrome for one)中存在安全异议