UPD1. I need to get the json file on the client’s machine, then it is processed and give the user the result.
UPD2. How to get data through HTTP on the client's machine using javascript.
UPD1. I need to get the json file on the client’s machine, then it is processed and give the user the result.
UPD2. How to get data through HTTP on the client's machine using javascript.
UPD1. I need to get the json file on the client’s machine, then it is processed and give the user the result.
Well, first, let's see what json is. Suppose that this is one of the species, i.e. set value pairs => property. We also assume that you have a JSON object called "test" for ease of understanding.
Then the problem is solved as follows:
var sc = document.createElement('script'); sc.src = 'путь к файлу, который отдаст json'; document.getElementsByTagName('head')[0].appendChild(sc); function readJson() { if (test) { // тут выполняем действия над объектом test } else { setTimeout(function() { readJson(); }, 1); } } readJson();
Do you want via JS to upload a file to the server from the user's computer? The browser will not let you do this for obvious reasons;).
You can make the usual form of sending a file to the page and manage it through JS (for example, make form.submit()
). But the user himself must initiate the file sending in any case.
Source: https://ru.stackoverflow.com/questions/2364/
All Articles