我正在尝试将数据json
从网站发送localhost
到网站domain.com
,但我发现jquery
使用时无法发送cross-domains
;
然后我阅读了jsonp
,现在我不知道如何编写代码;
不知何故,我需要news
用调用替换函数中的代码jsonp
;
<script>
function news(data) {
$.ajax({
'url': 'http://domain.com/index.php/api/news',
'data': {'data': data},
'success': function(data) {
},
dataType: 'json'
});
}
function unique(data) {
$.ajax({
'url': 'http://localhost/fb-group/index.php/api/unique',
'data': {'data': data},
'success': function(data) {
if (data && (data.status === 1) && data.news) {
news(data.news);
}
},
dataType: 'json'
});
}
access_token = 'token';
$.ajax({
'url': 'https://graph.facebook.com/453240374771082?fields=feed&method=GET&format=json&suppress_http_code=1&access_token=' + access_token,
'data': '',
'success': function(data) {
if (data && data.feed && data.feed.data) {
allData = data.feed.data;
$.each(allData, function(index, value) {
unique(value);
});
}
},
dataType: 'json'
});
</script>
这在服务器端可以吗?
这就是我如何捕获、解析和保存通过 ajax 调用收到的日期
public function actionNews() {
$data = json_encode($_GET['data']);
$data_decoded = json_decode($data);
// print_r($data_decoded);
$model_feedM = new FeedMLive();
$model_feedM->data_id = $data_decoded->id;
$model_feedM->data_from_name = $data_decoded->from->name;
$model_feedM->data_from_id = $data_decoded->from->id;
$model_feedM->data_to_data_name = $data_decoded->to->data[0]->name;
$model_feedM->data_to_data_id = $data_decoded->to->data[0]->id;
$model_feedM->data_message = strlen($data_decoded->message) > 0 ? $data_decoded->message : 'unknown';
$model_feedM->data_picture = isset($data_decoded->picture) ? $data_decoded->picture : 'unknown';
$model_feedM->data_link = isset($data_decoded->link) ? $data_decoded->link : 'unknown';
$model_feedM->views = 0;
$model_feedM->created = time();
$model_feedM->status = FeedM::ACTIVE;
if ($model_feedM->validate() && $model_feedM->save())
echo '{"status_live":"1"}';
else
echo '{"status_live":"0"}';
exit;
}