I am tring to write a page, which takes a RSS feed from a news site via AJAX and then sends it to PHP where I can work with it. The news feed is returned as an object array. I have tried posting it as it is, and also as a json string. The post method seems to be a success, but PHP gives an undefined index notice. This is my first time using AJAX and PHP and I seem to have problem with getting the data from the PHP side.
The error:
Notice: Undefined index: data in ...\index.php on line 33
Current code is the following:
ajax side
url = 'http://feeds.bbci.co.uk/news/rss.xml?edition=int';
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
error: function(){
alert('LOAD ERROR, INVALID URL');
},
success: function(xml){
values = xml.responseData.feed.entries;
var senddata = JSON.stringify(values);
console.log(senddata);
$.ajax({
type: "POST",
url: "index.php",
data: {data : senddata},
success: function(){
alert("postdone!");
},
error: function(){
alert("posterror!")
}
});
}
});
php side
<?php
$data = json_decode(stripslashes($_POST['data']));
echo $data;
?>
console.log(senddata);return anything?$_POST(var_dump($_POST);`) to see what it contains. Is your data there, perhaps in a place you didn't expect?