我有一個問題,我一直在試圖處理過去幾天。它開始困擾我.. 我似乎無法讓我的AJAX調用工作。我有一個簡單的表單,我試圖將參數發送到一個PHP腳本,但它不斷給我一個錯誤。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')");
有誰知道什麼是錯?請幫幫我。我真的很感激它:)
你有什麼錯誤?開發者控制檯說什麼? – 2014-09-06 14:20:06
如果這是一個你不妨礙默認瀏覽器提交的表單,請使用'preventDefault()'或返回'false' – charlietfl 2014-09-06 14:36:29
charlieftl!這解決了我的問題! :)非常感謝 - 我如何接受你的答案? – 2014-09-06 19:21:12