执行php脚本并使用js脚本中的ajax获取值

时间:2022-05-01 01:10:15

I've a A.php with somes inputs:

我有一些带有输入的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" />

I get them values in a B.js (and I re-use them for some things in JS)

我在B.js中得到它们的值(我在JS中重用它们用于某些东西)

var serverName = $.trim($('#serverName').val());
var serverIP = $.trim($('#serverIP').val());
var serverWebsite = $.trim($('#serverWebsite').val());

But now I've to write them in DB (php script) and I need to get this value again ? So it can be send in Ajax ?

但现在我要用DB(php脚本)编写它们,我需要再次获得这个值吗?那么可以用Ajax发送吗?

$.ajax({
url: "C.php",
method: "POST",
data: {
serverName: serverName.val(),
serverIP: serverIP.val(),
serverWebsite: serverWebsite.val()
},
dataType: "html"
});

Here my C.php will execute a post in DB with the variable serverName / serverWebsite / serverIP ? And this script can be launched with my ajax code ?

在这里,我的C.php将使用变量serverName / serverWebsite / serverIP在DB中执行一个帖子?这个脚本可以用我的ajax代码启动吗?

2 个解决方案

#1


0  

Your JavaScript change some code in Ajax like this

你的JavaScript改变了Ajax中的一些代码

$.ajax({
url: "C.php",
method: "POST",
data: {serverName: serverName,serverIP: serverIP,serverWebsite: serverWebsite },
dataType: "html",
success: function(ans){
alert(ans);
}
});

and here your c.php file code like this

在这里你的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  
?>

this code useful for you :)

这段代码对你有用:)

#2


0  

Your C.php would have code as below:

你的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.

?>

Thanks Amit

#1


0  

Your JavaScript change some code in Ajax like this

你的JavaScript改变了Ajax中的一些代码

$.ajax({
url: "C.php",
method: "POST",
data: {serverName: serverName,serverIP: serverIP,serverWebsite: serverWebsite },
dataType: "html",
success: function(ans){
alert(ans);
}
});

and here your c.php file code like this

在这里你的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  
?>

this code useful for you :)

这段代码对你有用:)

#2


0  

Your C.php would have code as below:

你的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.

?>

Thanks Amit