Hello!
Application logic:
HTML construction is managed by JS. At the initial access comes a standard page, depending on the user's actions, JS changes it accordingly.
Problem:
these actions entail requests to the server, where PHP pulls data from the database and forms a key-value array. Now I do not know how to pass this array to JS, bypassing jQuery or other third-party libraries.
In JS - a beginner, really want, bye, to do with standard tools.
- Good evening. For a beginner, just right jquery will do while you are dealing with pure js. - user216615
|
1 answer
Hey. You can do this:
In your php file, for example, post.php, get the data array you need:
<?php $postData = array( "error" => '123', "successInfo" => 'peivet', "email" => 'tets@gmail.com', ); echo json_encode($postData); After that, in your js file, for example script.js, you can get your entire array with data from your post.php file.
$(document).ready(function(){ $.ajax({ type: 'POST', url: 'post.php', success: function(result) { var data = jQuery.parseJSON(result); console.log(data); } }); }); Well, that's it, and now you have everything you need in the variable var data, do what is needed on the client side :) And that's all, you can immediately do in the success function.
- Thank. But I did not fully understand))) That is, I formed an array - I converted it to json. And how will he continue to catch his JS on the client side? - OO
|