[英]execute php script and get values with ajax from js script
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 ? 但是现在我必须用DB(php脚本)编写它们,我是否需要再次获取该值? So it can be send in Ajax ?
这样可以将其发送到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 ? 在这里,我的C.php将在数据库中执行一个变量serverName / serverWebsite / serverIP的发布? And this script can be launched with my ajax code ?
可以使用我的ajax代码启动该脚本吗?
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 谢谢阿米特
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 :) 此代码对您有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.