这就是我的javascript:
print "<script>function newpage(){
xmlhttp=new XMLHttpRequest();
var PageToSendTo = 'select_db.php?';
var MyVariable = 'variableData';
var VariablePlaceholder = 'variableName=';
var UrlToSend = PageToSendTo + VariablePlaceholder + MyVariable + '&tweet_id='" . $id_num;
print "xmlhttp.open('GET', UrlToSend);
xmlhttp.send();
}</script>";
(它在php文件中因此是print语句)
这是我的表单提交的样子:(再次在php语句中)
print "<form action=\"select_db.php\" onSubmit=\"return newpage()\">";
函数newpage无效..我希望变量在URL中发送,但结果URL只是select_db.php?
请帮忙。答案 0 :(得分:1)
您缺少初始<script>
代码...
print "<script>function newpage(){
xmlhttp=new XMLHttpRequest();
var PageToSendTo = 'select_db.php?';
var MyVariable = 'variableData';
var VariablePlaceholder = 'variableName=';
var UrlToSend = PageToSendTo + VariablePlaceholder + VariablePlaceholder + '$tweet_id='" . $id_num;
print "xmlhttp.open('GET', UrlToSend);
xmlhttp.send();
}</script>";
这可以解决你的问题吗?
答案 1 :(得分:0)
试试这个onSubmit=\"newpage(); return false; \"