I have a problem that I've been trying to deal with for the past couple of days. And it is starting to annoy me.. I can't seem to make my AJAX call work. I have a simple form and I'm trying to send the parameters to a php script, but it keeps giving me an error.
$("#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");
}
});
});
And this is 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')");
Does anyone know what is wrong? Please help me. I would really appreciate it :)
Try putting the full url starting from the http://...
You don't need to put ''
inside the data part. You can do it like:
data:{newspaper_id:newspaper_id,kategori_id:kategori_id,url:url,content:content,image:image}
For debugging; change your error function to :
error: function(xhr, textStatus, errorThrown){ alert(xhr + "," + textstatus + "," + errorThrown);}
so you can see what is wrong with your code.