2 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
我找到了一種工作方式。
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”中寫(xiě)入電話(huà)號(hào)碼。

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