[英]Ajax call to php script fails
在过去的几天里,我一直在尝试解决一个问题。 它开始使我烦恼。我似乎无法使我的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')");
有人知道哪里出问题了吗? 请帮我。 我真的很感激 :)
尝试从http://开始放置完整的URL。
您无需在数据部分中放入''
。 您可以像这样:
数据:{newspaper_id:newspaper_id,kategori_id:kategori_id,url:url,content:content,image:image}
用于调试; 将错误函数更改为:
错误:function(xhr,textStatus,errorThrown){alert(xhr +“,” + textstatus +“,” + errorThrown);}
这样您就可以查看代码有什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.