duanchuiwen6694 2016-06-22 13:23
浏览 13

AJAX Post为一个函数提供了404错误,但类似的函数运行正常

I am using jQuery and AJAX to run PHP functions without refreshing the page. It was working fine for my first two instances but I added a new one an now the new instance keeps giving me the following error

POST http://www.example.com/ajax.php 404 (Not Found)

I checked and rechecked and try to fin a similar error somewhere else by I am stumped. Here is my html

<img id="green" src="http://www.example.com/image/sign_no.jpg" onclick="runAjax(this.id)" />
<span id="blue" onclick="runAjax(this.id)">Press Here</span>

Here is my jQuery code

<script language="javascript">
    function runAjax(id) {
        if (id == "green") {
            if (document.getElementById("green").src == "http://www.example.com/image/sign_no.jpg") {
                document.getElementById("green").src = "http://www.example.com/image/sign_yes.jpg";
                $.ajax({
                    type: "POST",
                    url: "/ajax.php",
                    data:{action:"green_pressed",user_id:"' . $user_id . '"},
                    success:function(html) {
                        alert(id);
                    }
                });
            }
        }
        else if (id == "blue") {
            $.ajax({
                type: "POST",
                url: "/ajax.php",
                data:{action:"blue_pressed",run_id:"' . $run_id . '"},
                success:function(html) {
                    alert(id);
                }
            });

        }
    }
</script>

This is the ajax.php file

if($_POST['action'] == 'green_pressed') {
        print_r($_POST['user_id']);
}
if($_POST['action'] == 'blue_pressed') {
        print_r($_POST['run_id']);
}

So when I press the green id there is no issues, the code runs fine but when I press the blue id there is where I get the error. Any insights?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法