亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將變量傳遞給 php

將變量傳遞給 php

PHP
肥皂起泡泡 2023-04-15 20:27:50
我需要將變量“x”傳遞給 php,但我不知道如何傳遞。(我是 html 的新手。如果您需要更多信息,請告訴我。THX :D )function functionT() {  swal({      title: "For help",      text: "Write your phone number here and we will call you:",      type: "input",      showCancelButton: true,      closeOnConfirm: false,      animation: "slide-from-top",      inputPlaceholder: "ex: 0711342647"    },    function(inputValue) {      if (inputValue === false) return false;      if (inputValue === "") {        swal.showInputError("Try again");        return false      }      x = inputValue;      swal("", "You were added on our list: " + x, "success");    });}
查看完整描述

2 回答

?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

我找到了一種工作方式。


function functionT() {

  swal({

  title: "For help",

  text: "Write your phone number here and we will call you:",

  type: "input",

  showCancelButton: true,

  closeOnConfirm: false,

  animation: "slide-from-top",

  inputPlaceholder: "ex: 0711342647"

},

function(inputValue){

  if (inputValue === false) return false;


  if (inputValue === "") {

    swal.showInputError("Try again");

    return false

  }

  x = inputValue;




  swal("", "You were added on our list: " + x, "success");

  phone(x);

});

}

function phone(x){


var xmlhttp = new XMLHttpRequest();

  var xmlhttp = new XMLHttpRequest();

        xmlhttp.onreadystatechange = function() {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                res = xmlhttp.responseText;


            }

        };

  xmlhttp.open("GET", "php.php?x="+x, true);

  xmlhttp.send();

和PHP:


<?php

$myfile = fopen("newfile.txt", "a+") or die("Unable to open file!");

$phone_nr = $_GET['x'];

fwrite($myfile, $phone_nr);

fclose($myfile);

?> 

php 將在“newfile.txt”中寫入電話號碼。


查看完整回答
反對 回復 2023-04-15
?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

Javascript/Jquery 服務于客戶端,而 PHP 服務于服務器端,這意味著在發布表單/頁面之前,您不能將 x 值添加到 php 變量。簡單的解決方法是在表單元素中創建一個帶有 id myxinputbox 的隱藏輸入元素,在其中添加 x 值 -

document.getElementById('myxinputbox').value = x;

然后,當您發布表單時,將 x 添加到 php -

$posted_x = $_POST['myxinputbox'];


查看完整回答
反對 回復 2023-04-15
  • 2 回答
  • 0 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號