后端php接口代码,不能使用$_POST或$_GET,要使用file_get_contents
(
"php://input"
);例如下面:
<?php
// The request is a JSON request.
// We must read the input.
// $_POST or $_GET will not work!
$objData
= json_decode(
$data
);
// perform query or whatever you wish, sample:
/*
$query = 'SELECT * FROM
tbl_content
WHERE
title="'. $objData->data .'"';
*/
// Static array for this demo
$values
=
array
(
'php'
,
'web'
,
'angularjs'
,
'js'
);
// Check if the keywords are in our array
if
(in_array(
$objData
->data,
$values
)) {
echo
'I have found what you\'re looking for!'
;
}
else
{
echo
'Sorry, no match!'
;
}