Answer the question
In order to leave comments, you need to log in
When saving JSON via AJAX, why is only a certain number of files saved?
When trying to save json files, for some reason it saves only 112 files out of 122. What could be the problem?
$.ajax({
url: ajaxurl,
method: 'POST',
dataType: 'html',
data: data_agency,
async: false,
cache: false,
success: function (r) {
//получаем ответ от php скрипта
let result = JSON.parse(r);
//сохраняем полученные ID
data_json.agency[i].id_post = parseInt(result.id_post);
data_json.agency[i].user_id = parseInt(result.user_id);
//выводим информацию
$('.console').prepend('<p> > ======================================</p>');
$('.console').prepend('<p> > Создано агентство с ID ' + result.id_post + '</p>');
$('.console').prepend('<p> > Создано пользователь с ID ' + result.user_id + '</p>');
let data_save = data_json.agency[i];
let data_name = result.id_post + '.json';
//сохраняем полученную информацию в файл
$.post(ajaxurl, {action: 'nv_save_agency_json', data: {"agency": data_save}, name: data_name}, function (r){}, 'json');
}
});
add_action('wp_ajax_nv_save_agency_json', function () {
$fileName = $_POST['name'];
$myFile = NV_PARSER_DIR.'json/agency/'.$fileName;
$fh = fopen($myFile, 'w') or die('can\'t open file');
$stringData = json_encode($_POST['data']);
fwrite($fh, $stringData);
fclose($fh);
wp_die();
});
Answer the question
In order to leave comments, you need to log in
As it turned out, the volume of the post request was most likely exceeded. Rewrote for sending a string and not data and everything is ok.
Probably on the server side there is a plugin that gives results in parts and page by page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question