I have a button which when clicked I need to send two variables via a get request. If I just have one variable it works fine but as soon as I add the second one (str2) (called q) it doesnt do anything.
我有一个按钮,当点击时我需要通过get请求发送两个变量。如果我只有一个变量它工作正常,但只要我添加第二个(str2)(称为q)它不会做任何事情。
Script:
<script name="editresults">
function editresults(str,str2) {
if (str == "") {
document.getElementById("mainpart").innerHTML="";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("mainpart").innerHTML=xmlhttp.responseText;
}
$(document).ready(function() { $("#datepicker").datepicker({ dateFormat: 'dd-mm-yy', changeMonth: true,
changeYear: true, yearRange: '1930:2015'}); });
}
xmlhttp.open("GET","editemployeedetailsform.php?id="+str+"&q="+str2,true);
$('#editemployeedetailsform form').submit(function(){
var data=$(this).serialize();
// post data
$.post('submit.php', data , function(returnData){
$('mainpart').html( returnData)
})
return false; // stops browser from doing default submit process
});
xmlhttp.send();
}
}
</script>
Code for button:
按钮代码:
<td><input type='button' value='Edit' onclick='editresults(<?php echo $surnames[$k]["employeeid"] ?>,<?php echo $q ?>)'></td>
1 个解决方案
#1
0
It looks like it is not an problem with the ajax call, but with your mix of JavaScript and PHP. I guess the $surnames[$k]["employeeid"]
is a integer, wich works without quotation marks ["] but the second parameter <?php echo $q ?>
is probably a string an needs to be in quotation marks ["]
看起来它不是ajax调用的问题,而是你的JavaScript和PHP的混合。我猜$姓氏[$ k] [“employeeid”]是一个整数,它没有引号[“],但第二个参数 可能是一个需要用引号括起来的字符串[ “]
try this code for your button:
尝试使用此代码为您的按钮:
<td><input type='button' value='Edit' onclick='editresults(<?php echo $surnames[$k]["employeeid"] ?>,"<?php echo $q ?>")'></td>
more info: If the php interpreter adds a string like for example 'test' the result for the javascript interpreter my be onclick='editresults(1, test);'
Which means that test would be considered a variable.
更多信息:如果php解释器添加了一个字符串,例如'test',那么javascript解释器的结果就是onclick ='editresults(1,test);'这意味着测试将被视为变量。
#1
0
It looks like it is not an problem with the ajax call, but with your mix of JavaScript and PHP. I guess the $surnames[$k]["employeeid"]
is a integer, wich works without quotation marks ["] but the second parameter <?php echo $q ?>
is probably a string an needs to be in quotation marks ["]
看起来它不是ajax调用的问题,而是你的JavaScript和PHP的混合。我猜$姓氏[$ k] [“employeeid”]是一个整数,它没有引号[“],但第二个参数 可能是一个需要用引号括起来的字符串[ “]
try this code for your button:
尝试使用此代码为您的按钮:
<td><input type='button' value='Edit' onclick='editresults(<?php echo $surnames[$k]["employeeid"] ?>,"<?php echo $q ?>")'></td>
more info: If the php interpreter adds a string like for example 'test' the result for the javascript interpreter my be onclick='editresults(1, test);'
Which means that test would be considered a variable.
更多信息:如果php解释器添加了一个字符串,例如'test',那么javascript解释器的结果就是onclick ='editresults(1,test);'这意味着测试将被视为变量。