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

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

無法通過 HTML 表單調(diào)用函數(shù)

無法通過 HTML 表單調(diào)用函數(shù)

眼眸繁星 2023-03-24 14:46:00
我試圖通過提交按鈕調(diào)用一個(gè)函數(shù),但我無法提交它。<!DOCTYPE html><html><body><h2>API Call</h2><form method="post" action="display()">  <label for="gid">Global Device ID:</label><br>  <input type="text" id="gid" name="gid" value="m99002021" readonly><br>  <label for="type">Type:</label><br>  <input type="text" id="type" name="type" value="EVNT" readonly><br><br>  <label for="start">Start Date Time:</label><br>  <input type="text" id="start" name="start" value="2020-09-01 00:00:00" readonly><br><br>  <label for="end">End Date Time:</label><br>  <input type="text" id="end" name="end" value="2020-09-30 23:59:59" readonly><br><br>  <input type="submit" value="Execute"></form> <?phpfunction display(){  echo "hello".$_POST["gid"]."<br>";  echo "hello".$_POST["type"]."<br>";  echo "hello".$_POST["start"]."<br>";  echo "hello".$_POST["end"]."<br>";}if($_SERVER['REQUEST_METHOD']=='POST'){       display();} ?></body></html>單擊按鈕時(shí),execute我得到以下頁面網(wǎng)址是file:///C:/Users/Faisal/Desktop/display()
查看完整描述

3 回答

?
子衿沉夜

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

由于您現(xiàn)在使用 XAMPP 來使用 PHP,我們可以開始解決您的誤解。


在你的代碼中你有這一行

<form method="post" action="display()">


似乎您認(rèn)為該操作是要調(diào)用的 JavaScript 操作。但事實(shí)并非如此。


aaction的<form>不調(diào)用 JavaScript,但它會(huì)將包含所有表單數(shù)據(jù)的表單發(fā)送到此屬性中給定的 URL。display()由于您的屬性中有值action,因此瀏覽器會(huì)嘗試將數(shù)據(jù)發(fā)送到display()與您的表單 URL 相關(guān)的地址。但這是網(wǎng)絡(luò)服務(wù)器無法回答的地址,因此會(huì)發(fā)回 404 錯(cuò)誤。


我現(xiàn)在要問你的問題是:表格發(fā)送后會(huì)發(fā)生什么?表單數(shù)據(jù)應(yīng)該只寫入文檔嗎?我認(rèn)為這就是您想要實(shí)現(xiàn)的目標(biāo)。如果是,請(qǐng)嘗試此代碼。


<!DOCTYPE html>

<html>

<body>


<h2>API Call</h2>


<?php // Omit the action of the form. 

      // Now your PHP script will be called again, when the form is submitted

?>

<form method="post">

  <label for="gid">Global Device ID:</label><br>

  <input type="text" id="gid" name="gid" value="m99002021" readonly><br>

  <label for="type">Type:</label><br>

  <input type="text" id="type" name="type" value="EVNT" readonly><br><br>

  <label for="start">Start Date Time:</label><br>

  <input type="text" id="start" name="start" value="2020-09-01 00:00:00" readonly><br><br>

  <label for="end">End Date Time:</label><br>

  <input type="text" id="end" name="end" value="2020-09-30 23:59:59" readonly><br><br>

  <input type="submit" value="Execute">

</form> 


<?php

if($_SERVER['REQUEST_METHOD']=='POST')

{

  echo "hello".$_POST["gid"]."<br>";

  echo "hello".$_POST["type"]."<br>";

  echo "hello".$_POST["start"]."<br>";

  echo "hello".$_POST["end"]."<br>";


?>


</body>

</html>

此代碼中不涉及 JavaScript,因?yàn)槟恍枰?/p>


順便提一句。此代碼應(yīng)在 PHP 文件中,而不是 HTML 文件中


查看完整回答
反對(duì) 回復(fù) 2023-03-24
?
30秒到達(dá)戰(zhàn)場(chǎng)

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

只需從表單中刪除 display() 并單擊 Execute 按鈕。它會(huì)正常工作



查看完整回答
反對(duì) 回復(fù) 2023-03-24
?
RISEBY

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

像這樣嘗試


<!DOCTYPE html>

<html>

<body>


<h2>API Call</h2>


<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

  <label for="gid">Global Device ID:</label><br>

  <input type="text" id="gid" name="gid" value="m99002021" readonly><br>

  <label for="type">Type:</label><br>

  <input type="text" id="type" name="type" value="EVNT" readonly><br><br>

  <label for="start">Start Date Time:</label><br>

  <input type="text" id="start" name="start" value="2020-09-01 00:00:00" readonly><br><br>

  <label for="end">End Date Time:</label><br>

  <input type="text" id="end" name="end" value="2020-09-30 23:59:59" readonly><br><br>

  <input type="submit" value="Execute">

</form> 


<?php

function display()

{

  if(isset($_POST['submit'])

  {

    echo "hello".$_POST["gid"]."<br>";

    echo "hello".$_POST["type"]."<br>";

    echo "hello".$_POST["start"]."<br>";

    echo "hello".$_POST["end"]."<br>";

  }

}

if($_SERVER['REQUEST_METHOD']=='POST')

{

       display();


?>


</body>

</html>


查看完整回答
反對(duì) 回復(fù) 2023-03-24
  • 3 回答
  • 0 關(guān)注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報(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)