I would first recommend debugging what arrives at the server via AJAX. For this you can simply output values via var_dump() and can look at the response in the network tab of your browser.
Example:
function updateDataBase(){
var_dump($_POST);wp_die();
}
If you see here that ‘text’ is already truncated at this point, then your AJAX request would be responsible.
I see Headers parameter Content-Length: 2059630
in Chrome DevTools, but var_dump($_POST);
show me nothing in php function
What do you mean by “show me nothing in php function”? You should at least see an output like array() {}
if the POST request is empty.
On the html page, when I started AJAX request pushing on a button I see nothing changes;
function updateDataBase(){
global $wpdb;
$table_name = $wpdb->get_blog_prefix() . 'sports_viewer';
var_dump($_POST . ' dick');
print_r($_POST);
wp_die();
}
NO array.
Then the function will not be executed. Are you sure it is exactly this one? What comes back as response of the AJAX request?
I see request http://joxi.ru/Rmzy38McV9ZzXr
But when I show result AJAX in console I got –> http://joxi.ru/VrwxZ1JcgldQjm
I guess in your first screenshot you can see the post content. But this is not an array but a string, which is strange. Have a look at how you define the AJAX request in JavaScript.
My js code look like
async function getData() {
let response = await fetch('https://api1.test.com/');
if (!response.ok) {
const message = <code>An error has occured: ${response.status}</code>;
throw new Error(message);
}
let result = response.json();
return await result
}
$('#btn_update').click(function(){
getData().then((data) => {
const sportsJsonString = JSON.stringify(data, null, "\t");
console.log("sportsJsonString", sportsJsonString);
fetch(ajaxurl, {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: <code>action=updateDB&text=${sportsJsonString}</code>
})
.then((data) =>{
$('#btn_update').text('Повторно обновить');
})
.catch(err => console.error(err));
})
});
Why strange for you, that variable type of ‘sportsJsonString’ – string? If I push ‘data’ variable into table cell, I got [object Object]
in this json
cell.
During testing, I realized that the browser does not allow to write >415kB to the database (Chrome or FF makes no difference) It’s browser problem.
You can check it if you interrupt operations when accessing the file `wp-admin/admin-ajax.php’
The browser does not know about a database running only on the server. I am not even aware of such a limit. Where did you get this value?