Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果给定url参数,如何通过jQuery提交表单?_Javascript_Php_Jquery_Html_Forms - Fatal编程技术网

Javascript 如果给定url参数,如何通过jQuery提交表单?

Javascript 如果给定url参数,如何通过jQuery提交表单?,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,如果url中有触发器参数,我将尝试提交表单。到目前为止,我添加了一个代码段,以便自动将参数插入到输入字段中 这是我当前的代码,在使用submit按钮或Enter时工作正常 e、 g=>website.com/?lookup=value <form method="post" name="formid" id="formid"> <?php $paraid = $_GET['lookup']; ?> <input class="f

如果url中有触发器参数,我将尝试提交表单。到目前为止,我添加了一个代码段,以便自动将参数插入到输入字段中

这是我当前的代码,在使用submit按钮或Enter时工作正常

e、 g=>website.com/?lookup=value

<form  method="post" name="formid" id="formid">
     <?php $paraid = $_GET['lookup']; ?>   
          <input class="form-control" id="steamid" name="s" value="<?php echo $paraid; ?>" > 
              <input type="submit" id="invbtn"  value="submit" />
      </form>

      <script>
        $('#formid').submit(function() {
          var id = $("#steamid").val().replace(/(?:https?\:)?\/\//i, '');
          $.ajax({
            type: "GET",
            data: "s="+id,
            url: 'steam.php',
            beforeSend:function() {
              $("#outputinfo").html("<center><img src='./assets/img/load.gif'></br></br>Wait...</center>");
            },success: function(html) {
              $("#outputinfo").html(html);
            }
          });
          return false;
        });
        $(document).ready(function() {
          var id = '<?php echo $_GET['s']; ?>';
          if (id != null) {
            $.ajax({
              type: "GET",
              data: "s="+id,
              url: 'steam.php',
              beforeSend:function() {
                $("#outputinfo").html("<center><img src='./assets/img/load.gif'></br></br>Wait...</center>");
              },success: function(html) {
                $("#outputinfo").html(html);
              }
            });
          }
          return false;
        });
      </script>


若要提交url中包含特定单词的表单,请使用:

<?php if(isset($_GET['lookup'}) == 'value') :?> //whatever website.com/?lookup=value is
<script>
$(document).ready(function(){
    $('#formid').submit();
});
</script>
<?php endif ?>
//无论web.com/?lookup=值是多少
$(文档).ready(函数(){
$('#formid')。提交();
});

好的,很好!但是有50%的几率结果不会消失。。当我输入url时,列表会显示输出div()中的内容,但是10次中有5次div会再次被清除。代码似乎都在同时运行,这意味着表单在其他表单完成加载之前提交。确保两个ajax表单都在“$(document).ready(function(){”内,并放置php代码,使$('#formid').submit()脚本位于页面底部。您还可以尝试将submit更改为$(window).load(function()){因此它在ajax调用完成后提交。Isset返回true或false,因此比较永远不会为true。此外,右大括号真的应该是卷曲的吗?$(window.load(function())工作完成了吗非常非常非常抱歉再次打扰你:/i我测试了在空白页上只使用表单进行编码。现在我将代码复制并粘贴到我的网站(一页网站)当我在输入字段中手动输入值并单击submit时,效果很好,但是当我使用带有参数的url时,我无法向下滚动到表单或