$( document ).ready(function() {
$("#btn").click(
function(){
var dataf = {
"user": "Андрей",
"phone": "+380685743823",
"userID": "12342345423453",
};
var jsonString = JSON.stringify(dataf);
jQuery.ajax({
url: 'ТУТ ЮРЛ',
options: {
'Content-Type':'application/json' },
type: 'POST',
dataType: 'json',
data: jsonString,
success: function(response) {
document.getElementById('result_form').innerHTML = "Данные отправлены";
},
error: function(response) {
document.getElementById('result_form').innerHTML = "Ошибка. Данные не отправлены.";
}
});
}
);
});
public function actionBook() {
$data = $_POST['Book'];
$result = $this->saveBook($data);
}
public function actionTest() {
$data = [
'title' => 'Test title',
'desctiption' => 'Test description'
];
$result = $this->saveBook($data);
}
protected function saveBook($data) {
$model = new Book();
if ($model->load($data, '') && $model->validate()) {
retrun $model->save();
} else {
return false;
}
}
public function search()
{
$items = explode(" ",Request::get('words'));
$Articles = new Articles();
foreach ($items as $item){
$Articles->where('title', 'LIKE', '%' . $words . '%')
// $Articles->orWhere('title', 'LIKE', '%' . $words . '%') тут как хотите
}
$results = $Articles -> get();
return $results;
}