dourun2990 2015-07-19 20:05 采纳率: 100%
浏览 24
已采纳

如果给出url-parameter,如何通过jQuery提交表单?

I am trying to make a form be submitted if there is a trigger-parameter in the url. I so far added a code-snippet so automatically insert the parameter into the input field.

This is my current code, working perfectly when using the submit-button or 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>

Thanks in advance.. i hope you guys can help me out..

  • 写回答

1条回答 默认 最新

  • dongqin1075 2015-07-19 20:28
    关注

    To submit a form if it has a certain word in the url use:

    <?php if(isset($_GET['lookup'}) == 'value') :?> //whatever website.com/?lookup=value is
    <script>
    $(document).ready(function(){
        $('#formid').submit();
    });
    </script>
    <?php endif ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退