用php和ajax更新数据库

时间:2022-09-15 09:27:17

Below is my script that updates my characters position in my database:

下面是我的脚本,它更新了我的数据库中的字符位置:

<script language="javascript" type="text/javascript">
function positionUpdate(){
var word = document.getElementById('test').value;
var queryString = "?word=" + word;
ajaxRequest.open("GET", "new_position.php" + queryString, true);
ajaxRequest.send(null);
alert(queryString);
}
</script>

Next is the script that tells the above script to run but I need to send two variables across to it so it knows what to update.

接下来是告诉上面脚本运行的脚本,但我需要向它发送两个变量,以便它知道要更新的内容。

<a onClick="positionUpdate();"><img src="images/transparent.gif" border="0" /></a>

The link above is used multiple times so I need to send the values with that and not put the variables in the script at the top otherwise they would always be the same.

上面的链接被多次使用,所以我需要用它发送值,而不是将变量放在脚本的顶部,否则它们将始终是相同的。

As a note I am using the php GET function to retrieve the variables in position_update.php

作为一个注释,我使用php GET函数来检索position_update.php中的变量

Thanks, tanni

2 个解决方案

#1


Try:

<script language="javascript" type="text/javascript">
function positionUpdate(var1, var2){
    var word = document.getElementById('test').value;
    var queryString = "?word=" + word + "&var1=" + var1 + "&var2=" + var2;
    ajaxRequest.open("GET", "new_position.php" + queryString, true);
    ajaxRequest.send(null);
    alert(queryString);
}
</script>

and

<a onClick="positionUpdate('val1', 'val2');"><img src="images/transparent.gif" border="0" /></a>

Is that what you mean? It seems like a fairly basic question...

你是这个意思吗?这似乎是一个相当基本的问题......

#2


I don't understand your question.

我不明白你的问题。

Why don't you just pass the variables as function parameters to positionUpdate?

为什么不直接将变量作为函数参数传递给positionUpdate?

Maybe you could explain in a bit more detail what you are trying to accomplish.

也许你可以更详细地解释一下你想要完成的事情。

#1


Try:

<script language="javascript" type="text/javascript">
function positionUpdate(var1, var2){
    var word = document.getElementById('test').value;
    var queryString = "?word=" + word + "&var1=" + var1 + "&var2=" + var2;
    ajaxRequest.open("GET", "new_position.php" + queryString, true);
    ajaxRequest.send(null);
    alert(queryString);
}
</script>

and

<a onClick="positionUpdate('val1', 'val2');"><img src="images/transparent.gif" border="0" /></a>

Is that what you mean? It seems like a fairly basic question...

你是这个意思吗?这似乎是一个相当基本的问题......

#2


I don't understand your question.

我不明白你的问题。

Why don't you just pass the variables as function parameters to positionUpdate?

为什么不直接将变量作为函数参数传递给positionUpdate?

Maybe you could explain in a bit more detail what you are trying to accomplish.

也许你可以更详细地解释一下你想要完成的事情。