2

I restarted my old project and have a question regarding old code. 3 years ago I had this type of code to sent data from database to JavaScript arrays using php:

echo json_encode($result_array);

and JQuery:

$.ajax({
                    type : "POST",
                    url : "poli.php",
                    success : function(data) {
                        poli_owner = $.parseJSON(data);
                    },
                    async : false
                });

to populate JavaScript array.

My question is - is it still good code or not recommended anymore. If the code is not OK what code is better to use to take data from database and populate JavaScript array using php and JQuery? Thank you.

1 Answer 1

1

Yes, it is still good. All the web is still using Ajax and JSON.

Depending on your use case, you can load your data via a separate Ajax request, or just make your server-side language generate data for JS and include it in the page source code.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I am bad at programming and know only this method so I will use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.