发送的 Ajax 数据不起作用

ajax data sent wont work

本文关键字:数据 不起作用 Ajax      更新时间:2023-09-26

下面是一个ajax,但它不起作用,似乎有什么问题? 假设我有请求解析器.php里面有"echo "yes ajax work!";"。

$(document).ready(function(){
    // start ajax form submission
    $.ajax({
    url: "requestparser.php",
    type:"POST",
    data: ({ "pulldata" : "oy" }),
    success:function(e){
        if(($.trim(e)=="success")){
            alert("yes");
        }else{
            alert("no");     
        }
    },error:function(){
       alert("error");
    }
   }); 
});

如上所述的 ajax 函数,进程应该是,在加载时它将首先向 requestparser 发送一个 post 请求.php其帖子名称为 "pulldata",发布内容为 "oy",当 requestparser 收到来自 ajax 的 post 请求时,然后响应"是的 ajax 工作!"并且由于来自 requestparser 的响应.php不等于成功,那么它应该显示"否"。

任何帮助将不胜感激

我尝试调试您的代码,它对我来说效果很好。那么您可以尝试此代码并说出它显示的错误吗?

$(document).ready(function () {
    $.ajax({
        url: "test.php",
        type: "POST",
        data: ({
            "pulldata": "oy"
        }),
        success: function (e) {
            console.log(e);
        },
        error: function (e) {
            console.error(e);
        }
    });
});

test.php

<?php
var_dump($_POST);

还有一件事,只是为了确认,您在使用 ajax 之前已经在您的页面中包含 jQuery,对吗?