我有一些带有输入的A.php:
<input id="serverName" class="fullInput" type="text" name="serverName" placeholder="Nom du serveur" />
<input id="serverIP" class="fullInput" type="text" name="ip" placeholder="Adresse IP" />
<input id="serverWebsite" class="fullInput" type="text" name="site" placeholder="URL du site" />
我在B.js中得到它们的值(我在JS中重复使用它们)
var serverName = $.trim($('#serverName').val());
var serverIP = $.trim($('#serverIP').val());
var serverWebsite = $.trim($('#serverWebsite').val());
但是现在我要用DB(php脚本)写它们,我需要再次获得这个值吗?那么它可以在Ajax中发送吗?
$.ajax({
url: "C.php",
method: "POST",
data: {
serverName: serverName.val(),
serverIP: serverIP.val(),
serverWebsite: serverWebsite.val()
},
dataType: "html"
});
这里我的C.php将使用变量serverName / serverWebsite / serverIP在DB中执行一个帖子?这个脚本可以用我的ajax代码启动吗?
答案 0 :(得分:0)
你的C.php会有如下代码:
<?php
$serverName = $_POST['serverName'];
$serverIP= $_POST['serverIP'];
$serverWebsite= $_POST['serverWebsite'];
//here you need to write mysql code to insert it in to database or whatever process you want to do with this variables.
?>
由于 阿米特
答案 1 :(得分:0)
您的JavaScript更改了Ajax中的一些代码
$.ajax({
url: "C.php",
method: "POST",
data: {serverName: serverName,serverIP: serverIP,serverWebsite: serverWebsite },
dataType: "html",
success: function(ans){
alert(ans);
}
});
这里你的c.php文件代码就像这样
<?php
$serverName = $_POST['serverName'];
$serverIP= $_POST['serverIP'];
$serverWebsite= $_POST['serverWebsite'];
//here you need to write mysql code to insert it in to database or whatever process
?>
此代码对您有用:)