第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

頁面加載時(shí)如何運(yùn)行ajax jquery的第一個(gè)實(shí)例

頁面加載時(shí)如何運(yùn)行ajax jquery的第一個(gè)實(shí)例

我有一個(gè) jquery 和 ajax 執(zhí)行查詢并在單擊按鈕時(shí)顯示一個(gè)表。問題是當(dāng)頁面第一次加載時(shí),查詢沒有運(yùn)行并且不顯示任何內(nèi)容,因此必須單擊按鈕才能開始顯示查詢結(jié)果。有沒有辦法在頁面加載時(shí)運(yùn)行查詢?然后只需使用按鈕。我的代碼是:$(document).ready(function() {  $("#display").click(function() {    $.ajax({ //create an ajax request to display.php      type: "GET",      url: "genquery.php",      dataType: "html", //expect html to be returned                      success: function(response) {        $("#responsecontainer").html(response);        //alert(response);      }    });  });});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><table border="1" align="center">  <tr>    <td> <input type="button" id="display" value="Buscar" /> </td>  </tr></table><div id="responsecontainer" align="center"></div>
查看完整描述

2 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

只需調(diào)用click()元素來模擬點(diǎn)擊。


$(document).ready(function() {

  $("#display").click(function() {

    $.ajax({ //create an ajax request to display.php

      type: "GET",

      url: "genquery.php",

      dataType: "html", //expect html to be returned                

      success: function(response) {

        $("#responsecontainer").html(response);

        //alert(response);

      }

    });

  }).click();

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<table border="1" align="center">

  <tr>

    <td> <input type="button" id="display" value="Buscar" /> </td>

  </tr>

</table>

<div id="responsecontainer" align="center">


</div>


查看完整回答
反對(duì) 回復(fù) 2022-10-14
?
侃侃爾雅

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超16個(gè)贊

您可以提取您在點(diǎn)擊處理程序中調(diào)用的函數(shù)并在ready.


$(document).ready(function() {

  const displayContent = () => {

    $.ajax({ //create an ajax request to display.php

      type: "GET",

      url: "genquery.php",

      dataType: "html", //expect html to be returned                

      success: function(response) {

        $("#responsecontainer").html(response);

        //alert(response);

      }

    });

  }

  displayContent();

  $("#display").click(displayContent());

});


查看完整回答
反對(duì) 回復(fù) 2022-10-14
  • 2 回答
  • 0 關(guān)注
  • 136 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)