I am creating a page that will read, write, and modify data in a mysql database. I am using php with codeigniter to perform the queries however the page that the user will see I am powering with javascript, dynamically filling and changing the data based on the user selections. To do this I am passing lots of data back and forth from php to javascript functions and vice versa, but I am wondering if there is a better way of formatting the data. For example here is a javascript function that uses XMLHttpRequest to call a php function and get the result:
var myarray = new Array(2);
myarray[0] = document.getElementById("my_input").value;
myarray[1] = document.getElementById("my_select").value;
xmlhttp.open("POST", "my_url/my_function/"+myarray.join('|'), false);
xmlhttp.send();
document.getElementById("my_element").innerHTML=xmlhttp.responseText;
I simply do an explode() on the string passed to the php function and execute the necessary queries. This seems like a very awkward interaction between php and javascript. Is there a better, or at least different, way to do this?
json_encodeandjson_decodemethods detailed here: php.net/manual/en/book.json.php