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”中寫入電話號碼。

TA貢獻1799條經驗 獲得超6個贊
Javascript/Jquery 服務于客戶端,而 PHP 服務于服務器端,這意味著在發布表單/頁面之前,您不能將 x 值添加到 php 變量。簡單的解決方法是在表單元素中創建一個帶有 id myxinputbox 的隱藏輸入元素,在其中添加 x 值 -
document.getElementById('myxinputbox').value = x;
然后,當您發布表單時,將 x 添加到 php -
$posted_x = $_POST['myxinputbox'];
- 2 回答
- 0 關注
- 132 瀏覽
添加回答
舉報