getting a json string in php from jquery ajax post -


i tring write page, takes rss feed news site via ajax , sends php can work it. news feed returned object array. have tried posting is, , json string. post method seems success, php gives undefined index notice. first time using ajax , php , seem have problem getting data php side.

the error:

notice: undefined index: data in ...\index.php on line 33 

current code 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;          ?> 

wrap code in if avoid warning:

if (isset($_post['data'])) {     $data = json_decode(stripslashes($_post['data']));     echo $data;   } 

the problem when visit index.php browser, there no post request, of course $_post empty , $_post['data'] not set.

hope point.

edit:

hmm can't see wrong. , recommend use php.net/manual/en/book.curl.php data directly rss, instead of nesting 2 ajax calls.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -