JavaScript 功能
function sub()
{
var url = "showpdf.php";
$.ajax({
type: "post",
url: url,
success: function(response)
{
document.getElementById("alldata").innerHTML = response;
}
});
}
我在html中调用此函数,如下所示:
<input type = "button" value="Go" onclick="sub()">
在showpdf.php
文件中我写了下面的代码来获取表单数据
$academic = $_POST['academic'];
$uni = $_POST['University'];
但我收到此错误
未定义的索引:学术
答案 0 :(得分:1)
您需要将数据输入到ajax调用中,此时您实际上并没有向php脚本发送任何内容。
您可以按如下方式将数据添加到您的ajax调用
function sub()
{
var url = "showpdf.php";
$.ajax({
type: "post",
url: url,
data: {'academic': 'wiiiieee'},
success: function(response)
{
document.getElementById("alldata").innerHTML = response;
}
});
}
其中data
是包含key-&gt;值对的对象
答案 1 :(得分:1)
将数据传递给ajax调用:
例如:
//将您的帖子数据输入这些变量
var University;
var academic;
//并将其传递给
var dataString = 'academic='+ academic+ '&University=' + University;
$.ajax({
type: "post",
data: dataString,
url: url,
success: function(response)
{
document.getElementById("alldata").innerHTML = response;
}
});
答案 2 :(得分:1)
您应该从输入字段中获取数据并通过ajax post call
发送function sub()
{
var url = "showpdf.php";
var university = jQuery("#university").val(); //id of the university input field
var academic = jQuery("#academic").val(); // id of the academic input field
$.ajax({
type: "post",
url: url,
data: { university: university, location: academic },
success: function(response)
{
document.getElementById("alldata").innerHTML = response;
}
});
}
答案 3 :(得分:0)
您没有通过ajax调用发送任何数据。
function sub(data)
{
var url = "showpdf.php";
$.ajax({
type: "post",
data: data,
url: url,
success: function(response)
{
document.getElementById("alldata").innerHTML = response;
}
});
}
var data = {"academic": "something", "University": "something else"};
sub(data);
答案 4 :(得分:0)
function sub(){
var url =&#34; showpdf.php&#34;;
var dataString = $(&#34;#form&#34;)。serialize();
$。AJAX({
类型:&#34;发布&#34;,
url:url,
数据:dataString,
成功:功能(响应)
{
document.getElementById(&#34; alldata&#34;)。innerHTML = response;
}
});
}