There was a need to make a "script" on the PCP page that will send back the json file to the sent request:
{"count":/\*любая цифра\*/} How to implement this so that php can still verify the data? js sends via $.ajax
There was a need to make a "script" on the PCP page that will send back the json file to the sent request:
{"count":/\*любая цифра\*/} How to implement this so that php can still verify the data? js sends via $.ajax
Do this:
Js
$.post('/url/', data ,function(response){ response = JSON.parse(response); switch (response['status']){ case 1: $('#block').html(response['count']); break; case 0: console.log('Произошла ошибка'); break; } }); Php
<? // Получаете данные switch (gettype($_POST['data'])){ case string: // Делаете действия с данными break; case object: // Тут тоже можно что-то делать break; } That is, at the beginning, you need to know the type of data before checking. Type validation is always a good thing.
<?php $number = 5; $res['count'] = $number; echo json_encode($res); ?> Source: https://ru.stackoverflow.com/questions/482015/
All Articles