簡體   English   中英

頁面加載提交輸入

[英]On page load submit input

    <script>$(function(){

        $('#url').keypress(function(event) {
            var v_url = $('#url').val();
            if(event.which == 13 && v_url!=""){
                $('#res').html("Loading...");
                doajax(v_url);
            }
        });

        function doajax(url){
            $.ajax({
                url: 'getdata.php',
                dataType: 'json',
                data: {url: url},
            })
            .done(function(data) {
                var h3 = $('<h3>').html("Loading"),
                box = $('#res').html("").append(h3);
                for(var i=0;i<data.length;i++){
                    box
                    .append('<ul>')
                    .append("<li>"+data[i].email+"</li>")
                    .append("<li><a href='"+data[i].name+"'>"+data[i].lastname+"</a></li>")
                    .append("<ul>");
                }
            }).fail(function(){
                $('#res').html('Error');
            });
        }

    });

 </script>
<input type="text" id="url" value="https://www.example.com<?php echo $_SERVER['REQUEST_URI']; ?>" style="width:600px;height:30px;font-size:25px">

頁面加載后如何提交此輸入?

我提交此輸入的唯一方法是按ENTER鍵。

我試圖做一個按鈕提交,但沒有用。

我這樣做是因為,例如,我輸入www.example.com/BillGates,並且當我輸入此頁面URL時,我使用php代碼來獲取當前頁面的URL,所以當我打開頁面時,我會將其輸入輸入值中除了在輸入表單中按Enter鍵外,其他人員都不想,但是我希望頁面加載時自動獲得結果,因此他們不需要按Enter鍵。

好吧,你可以做到這一點.............

 $(document).ready(function(){

      $("#enter_key_id").click();

 });

在頁面加載時單擊您的輸入按鈕。

您無法提交輸入,但可以提交表格:

在您的PHP中:

<form id="form-id" action="url.php" method="POST">
  /* better hidden than text if you don't want to the user can change it */
  <input type="hidden" name="url" value="http://www.example.com...<?php print $anything; ?>" />
</form>

在您的JS中:

$(document).ready(function() {
  $('#form-id').submit();
});

但是我不明白為什么你需要這樣做。 從第一個PHP進行curl調用更好嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM