I have 15k of JSON products that i need to process with PHP, if i var_dump the array i have no problems. if i reduce the JSON datas to 1000-1500 it takes 1/2 seconds, and the user interface composed by two buttons that do some jquery actions takes some seconds. The problem is obviusly when i pass all datas(15k), it takes 40/50 seconds to display HTML page and if i click buttons they don't work.
this is what i do: getting JSON from an external URL, (no problems). passing JSON using AJAX(POST) to PHP, (no problems). getting string in PHP file, encode the string in array and process each data, after data_processing is okay i'm echoing datas as
<?
echo'<div class="myclass" id="myid">';
echo'<input type="hidden" value="somedatas">';
echo'<input type="text" name="'.$json[$_POST["SOMEDATA"]].'" value="somedatas">";
....
?>
is there a better method to do that? i also tried to set display:none
to main div, but no changes.
UPDATE i forgot a pass, the php echo is turned back to an ajax request and appended to a div
this is the script that i use to process data one by one once confirm button is clicked
echo'<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#close_tab_prw").click(function(){
document.getElementById("prd_prw_tab").innerHTML = ""; //reset div
$("#prd_prw").css("display","none");
$("#container_others").css("opacity","1");
});
$("#update_all_items").click(function(){
var prd_number = $("input[name=prd_max_number]").val();
for(var i = 0; i < prd_number; i++){
var string_ok = "#confirm_form_prd_";
string_ok = string_ok.concat(i);
var dataString = $(string_ok).serialize();
$.ajax( {
type: "POST",
url: "';echo $dir; echo'",
data: dataString,
success: function(data) {
console.log(data);
$("#prd_prw_tab").html(data);
}
});
}
});
$("#disable_img").click(function(){
$(".img_check").prop("checked", false);
});
$("#allow_img").click(function(){
$(".img_check").prop("checked", true);
});
$("#disable_desc").click(function(){
$(".n_desc_chk").prop("checked", false);
});
$("#allow_desc").click(function(){
$(".n_desc_chk").prop("checked", true);
});
});
</script>';
and this is the main function that i use to display products:
$(document).ready(function(){
$("#get_json_btn").click(function(){
document.getElementById("unique_json_return").innerHTML = ""; //reset div
if(document.getElementById('url_json').value != "") {
$.getJSON(document.getElementById('url_json').value , function(result){
$.each(result, function(i, field){
$("#unique_json_return").append(JSON.stringify(result));
})
})
.fail(function() { alert('getJSON request failed, see tips '); })
}
else {
alert("No Url insrted, please, insert your JSON url");
}
});
$("#update_products").click(function(){
new_height = "";
$( window ).resize(function() {
$("#prd_prw").css("height", $(window).height()-(20*$(document).height()/100));
});
new_height = $(window).height()-(20*$(document).height()/100);
$("#prd_prw").css("height", new_height);
$("#prd_prw").css("display","block");
$("#container_others").css("opacity","0.3");
var entire_json = document.getElementById('unique_json_return').innerText;
var one = document.getElementsByName('one')[0].value;
var two = document.getElementsByName('two')[0].value;
...
var ten = document.getElementsByName('ten')[0].value;
if(entire_json == "") {
alert("Invalid or Empty JSON response");
}
else{
$.ajax({
url: '<?echo $dir; ?>',
data: {entire_json : entire_json, one:one, two:two, three:three,...ten:ten
},
type: 'POST',
success: function(data) {
document.getElementById("unique_json_return").innerHTML = ""; //reset div
$("#prd_prw_tab").append(data);
}
});
}
});
});