将变量传递给 php

我需要将变量“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");


    });

}


肥皂起泡泡
浏览 107回答 2
2回答

不负相思意

我找到了一种工作方式。function functionT() {&nbsp; swal({&nbsp; title: "For help",&nbsp; text: "Write your phone number here and we will call you:",&nbsp; type: "input",&nbsp; showCancelButton: true,&nbsp; closeOnConfirm: false,&nbsp; animation: "slide-from-top",&nbsp; inputPlaceholder: "ex: 0711342647"},function(inputValue){&nbsp; if (inputValue === false) return false;&nbsp; if (inputValue === "") {&nbsp; &nbsp; swal.showInputError("Try again");&nbsp; &nbsp; return false&nbsp; }&nbsp; x = inputValue;&nbsp; swal("", "You were added on our list: " + x, "success");&nbsp; phone(x);});}function phone(x){var xmlhttp = new XMLHttpRequest();&nbsp; var xmlhttp = new XMLHttpRequest();&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.onreadystatechange = function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = xmlhttp.responseText;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; xmlhttp.open("GET", "php.php?x="+x, true);&nbsp; 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);?>&nbsp;php 将在“newfile.txt”中写入电话号码。

哈士奇WWW

Javascript/Jquery 服务于客户端,而 PHP 服务于服务器端,这意味着在发布表单/页面之前,您不能将 x 值添加到 php 变量。简单的解决方法是在表单元素中创建一个带有 id myxinputbox 的隐藏输入元素,在其中添加 x 值 -document.getElementById('myxinputbox').value&nbsp;=&nbsp;x;然后,当您发布表单时,将 x 添加到 php -$posted_x&nbsp;=&nbsp;$_POST['myxinputbox'];
打开App,查看更多内容
随时随地看视频慕课网APP