【发布时间】:2012-06-05 13:54:31
【问题描述】:
我有一个使用 JQuery 中的 .post 函数来运行 php 脚本的站点。此脚本将一些数据添加到数据库中,但如果数据已存在于数据库中,则不会添加数据。根据是否添加数据,我希望 javascript 做不同的事情。我不知道如何让 php 返回一个表示“输入数据”或“未输入数据”的值,以便 javascript 可以使用该值来决定下一步操作。
这是 javascript,我只希望在 php 返回数据已输入数据库的情况下进行追加。
$('#addpios').click(function() {
var scopesheetidvalue = $("#scopesheetid").val();
var piovalue = $("#pioselected").val();
$.post("addpio.php", { scopesheetid: scopesheetidvalue, pionumber: piovalue },function(data){
$('#pioslist').append("<li><input class='removepio' type='submit' value='"+piovalue+"' /><span class='listitem'>PIO "+piovalue+"</span></li>");}
);
});
这里是 PHP
$scopesheetid = $_POST['scopesheetid'];
$pionumber = $_POST['pionumber'];
$alreadyexisitssql = "SELECT * FROM [ScopesheetPIO] WHERE [ScopesheetID]='$scopesheetid' AND [PIONumber]='$pionumber'";
$alreadyexisits=odbc_exec($connection,$alreadyexisitssql);
if(odbc_fetch_row($alreadyexisits)){
//retrun a value that says the data already exists
}
else{
$addpiosql = "INSERT INTO [ScopesheetPIO] ([ScopesheetID], [PIONumber]) VALUES ('$scopesheetid', '$pionumber')";
$addpioresult=odbc_exec($connection,$addpiosql);
//retrun a vlaue that the data was added
}
我真正想要的是一种将 PHP 脚本中的值传递回 Jquery 的方法
【问题讨论】: