Ajax对php脚本的调用失败

时间:2014-09-06 14:19:08

标签: php jquery ajax

我有一个问题,我过去几天一直试图解决这个问题。它开始惹恼我了.. 我似乎无法让我的AJAX调用工作。我有一个简单的表单,我试图将参数发送到PHP脚本,但它一直给我一个错误。

  $("#submitRSS").click(function() {

        var newspaper_id = $("#aviser").find('option:selected').attr("newspaper_id");
        var kategori_id = $("#kategorier").find('option:selected').attr("category_id");
        var url = $("#urlRSS").val();
        var content = $("#contentRSS").val();
        var image = $("#imageRSS").val();

        $.ajax({
                url:'insert_crawler_RSS.php',
                type:'GET',
                data:{'newspaper_id':newspaper_id,'kategori_id':kategori_id,'url':url,'content':content,'image':image},

                success: function (res) {
                    $("#message").append('<div class="alert alert-success" role="alert">Godt arbejde!</div>');
                },
                error: function() {
                    //$("#message").append('<div class="alert alert-danger" role="alert">Noget gik galt :(</div>');
                    alert("error");
                }

        });

    });

这是insert_crawler_RSS.php:

    if(isset($_GET['newspaper_id'])) {
        $newspaper_id = $_GET['newspaper_id'];
    }

    if(isset($_GET['kategori_id'])) {
        $category_id = $_GET['kategori_id'];
    }

    if(isset($_GET['url'])) {
        $url = $_GET['url'];
    }

    if(isset($_GET['content'])) {
        $content = $_GET['content'];
    }

    if(isset($_GET['image'])) {
        $image = $_GET['image'];
    }

    mysqli_query($con,"INSERT INTO crawler_urls (url,newspaper_id,rss,category_id) VALUES('$url','$newspaper_id','1','$category_id')");
    mysqli_query($con,"INSERT INTO crawlers (content_xpath,newspaper_id,image_xpath) VALUES('$content','$newspaper_id','$image')");

有谁知道出了什么问题?请帮我。我真的很感激它:)

1 个答案:

答案 0 :(得分:-1)

  1. 尝试从http:// ...

  2. 开始填写完整的网址
  3. 您无需将''放入数据部分。你可以这样做:

    数据:{newspaper_id:newspaper_id,kategori_id:kategori_id,网址:URL,内容:内容,图像:图像}

  4. 用于调试;将您的错误功能更改为:

    错误:function(xhr,textStatus,errorThrown){ alert(xhr +“,”+ textstatus +“,”+ errorThrown);}

  5. 这样您就可以看到代码出了什么问题。