So im trying to send an object array to a js function anytime I push a button.
<button onclick="actualizarProcesos(<?php echo json_encode($p_array)?>);">X</button>
I’ve made sure my json isnt sending any weird characters as it is mostly int except for the object attribute “name” which is string.
That function is in a different js file:
function actualizarProcesos(p_array){
var p = JSON.parse(p_array);
}
At the moment I’m trying to send make sure the function is receiving the data but it keeps throwing the error Uncaught SyntaxError: Unexpected end of input
So I’m stuck trying to find out how to fix the error.
I plan afterwards on sending that array to another php file using ajax, something like this:
$.ajax({
type: "POST",
url: "post.php",
data: JSON.stringify(values),
success: function(data){
alert(data)
}
});
This is the full json I’m trying to send
[{"name":"A","t_arrival":7,"t_est":25,"state":1,"pages":5,"mem_data":[[1,8,13,5,0,1],[0,0,0,0,0,0],[1,11,17,3,1,1],[1,12,16,4,0,1],[0,0,0,0,0,0]],"t_rem":25,"t_wait":0,"rem_quantum":0},{"name":"B","t_arrival":6,"t_est":13,"state":2,"pages":4,"mem_data":[[0,0,0,0,0,0],[1,9,16,5,0,1],[1,7,14,6,1,0],[0,0,0,0,0,0]],"t_rem":13,"t_wait":0,"rem_quantum":0},{"name":"C","t_arrival":8,"t_est":37,"state":3,"pages":3,"mem_data":[[1,9,12,2,0,0],[0,0,0,0,0,0],[1,13,21,7,0,1]],"t_rem":37,"t_wait":0,"rem_quantum":0}]
3
Answers
you can do it by this way
}
Tested working fine. Hope this help you.
Strings in JSON are delimited with
"
characters.Your HTML attribute value is delimited with
"
characters.The
"
in the data will cut off the attribute value.You need to encode your data (using
htmlspecialchars
) for embedding in HTML: