1

可能我正沉入一个空玻璃杯中,或者我在这个项目上花了太多时间,但它就是这样:我想从一个 htm 文件中使用 jquery 调用一个 php 脚本。

我的jQuery代码:

$.ajax({
    type: "POST",
    url: "localhost/calculate/vr4/getAmount.php",
    data: "from="+ from_date +"&enddate=" + end_date,
    success: function(info){
        alert("test info : " + info);
    }
});

php脚本:

$testdate=$_POST['from'];

if ($testdate==NULL)
{
echo "No text";
}
else
{
echo "a date";
}

什么也没发生,我在 url 中注意到了这一点:

http://localhost/calculate/vr4/summary_q.php?consult_range.x=30&consult_range.y=5

这些参数(consult_range)是我将click事件与jquery绑定的类名。任何指针?我已经尝试了这个论坛和其他人的几个代码示例,我得到了相同的结果。希望有人回答,我知道有点晚了

4

2 回答 2

0

您正在以 GET 格式传递数据,我猜由于您在 php 中使用 $_POST,因此您会收到错误,因为没有 Post 数据。在 ajax 调用中,您需要将数据作为我认为的对象传递。但只是为了检查我是否正确将 $_POST 更改为 $_GET

更新

在您的 ajax 调用中使用

data: {from: from_date, enddate: end_date}

于 2012-06-19T04:36:46.017 回答
0

试试这个方法

$.ajax({ type: "POST", url: "http://localhost/calculate/vr4/getAmount.php", data: "from="+ from_date +"&enddate=" + end_date, 成功: function(info ){ alert("测试信息:" + info); } });

或者

$.ajax({ type: "POST", url: "vr4/getAmount.php", data: "from="+ from_date +"&enddate=" + end_date, success: function(info){ alert("test info : " + 信息); } });

于 2012-06-19T06:00:37.143 回答