|
From: Ted H. <meg...@gm...> - 2024-08-19 17:52:57
|
I keep hitting a stone wall. If I write my code like this:
function Setup() {
var XMLHttp;
var JSON_Data;
XMLHttp = new XMLHttpRequest();
XMLHttp.open("GET", "
http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json", true);
document.getElementById("JSON_Text").value = "I'm right here.";
}
The words I'm right here appear in the textbox.
But if I write my code like this:
function Setup() {
var XMLHttp;
var JSON_Data;
XMLHttp = new XMLHttpRequest();
XMLHttp.open("GET", "
http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json", true);
XMLHttp.onReadyStateChange = function(){
document.getElementById("JSON_Text").value = "I'm right here.";
};
}
Nothing appears in my textbox. And I don't understand why. Can someone
please explain this to me?
On Mon, Aug 19, 2024 at 12:16 PM Ted Hickox <meg...@gm...> wrote:
> One more update. I was stupid. I forgot to replace the variables. Now I
> get undefined when I run the javascript code.
>
> function Setup() {
> var XMLHttp;
> var JSON_Data;
>
> XMLHttp = new XMLHttpRequest();
> XMLHttp.open("GET", "
> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json", true);
> XMLHttp.onreadystatechange = function () {
> if(XMLHttp.readystate == 4) {
> JSON_Data = XMLHttp.responseText;
> JSON_Data = JSON.parse(JSON_Data);
> }
> };
>
> document.getElementById("JSON_Text").value = JSON_Data;
>
>
> }
>
> On Mon, Aug 19, 2024 at 12:04 PM Ted Hickox <meg...@gm...> wrote:
>
>> I updated my code again and now nothing appears in the textbox. This is
>> truly frustrating.
>>
>> javascript document:
>>
>> function Setup() {
>>
>> XMLHttp = new XMLHttpRequest();
>> XMLHttp.open("GET", "
>> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json",
>> true);
>> XMLHttp.onreadystatechange = function () {
>> if(XMLHttp.readyState == 4){}
>> document.getElementById("JSON_Text").value = "Taking another
>> step.";
>>
>> };
>> }
>>
>> On Mon, Aug 19, 2024 at 11:33 AM Ted Hickox <meg...@gm...> wrote:
>>
>>> I fixed a couple of errors and got some new responses. But I still
>>> didn't get the responses I needed.
>>>
>>> Here is my new Javascript document:
>>>
>>> function Setup() {
>>>
>>> XMLHttp = new XMLHttpRequest();
>>> XMLHttp.open("GET", "
>>> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json",
>>> true);
>>> XMLHttp.onreadystatechange = function () {
>>> if(XMLHttp.readyState == 4){}{
>>> JSON_Data = XMLHttp.responseText;
>>> JSON_Data = JSON.parse(JSON_Data);
>>> document.getElementById("JSON_Text").value = JSON_Data;
>>> }
>>>
>>> };
>>> }
>>>
>>> And here is my new people.json
>>>
>>> {"name":"John", "age":30, "city":"New York"}
>>>
>>> And here is the new response from the HTML textbox:
>>>
>>> [object Object]
>>>
>>> I'm still not sure what I'm doing wrong.
>>>
>>> On Mon, Aug 19, 2024 at 10:06 AM Florian Schmitt <
>>> ml-...@fl...> wrote:
>>>
>>>> Ted, if your resource is named People.json in eXist (with upper-case
>>>> "P"), you'll need to adapt your URL accordingly. Currently, the URL points
>>>> to people.json, not People.json.
>>>>
>>>> 19.08.2024 07:25:51 Ted Hickox <meg...@gm...>:
>>>>
>>>> My apology for giving you incorrect Javascript code. I corrected my
>>>> code. Here it is:
>>>>
>>>> function Setup() {
>>>> var XMLHttp;
>>>> var JSON_Data;
>>>>
>>>>
>>>> XMLHttp = new XMLHttpRequest();
>>>> XMLHttp.open("GET", "
>>>> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json",
>>>> true);
>>>> XMLHttp.onreadystatechange = function () {
>>>> if(XMLHttp.readyState == 4){}{
>>>> JSON_Data = XMLHttp.responseText;
>>>> document.getElementById("JSON_Text").value = JSON_Data;
>>>> }
>>>>
>>>> };
>>>>
>>>> }
>>>>
>>>> When I run the code and check the console, it states that it can't find
>>>> people.json. I don't know why my webpage can't find people.json Can you
>>>> assist me?
>>>>
>>>> On Sun, Aug 18, 2024 at 11:42 AM Jean-Paul Rehr <re...@gm...>
>>>> wrote:
>>>>
>>>>> Ted, none of this has to do with eXist parsing JSON.
>>>>>
>>>>> The URL
>>>>> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json is
>>>>> requesting a JSON document from eXist, that is, eXist is serving the
>>>>> document not parsing it.
>>>>>
>>>>> Incidentally, one can parse a json document in Xquery with the
>>>>> command:
>>>>>
>>>>> fn:json-doc("/db/apps/HTML_Student/people.json")
>>>>>
>>>>> JPR
>>>>>
>>>>> On Sun, Aug 18, 2024 at 6:26 PM Ted Hickox <meg...@gm...>
>>>>> wrote:
>>>>>
>>>>>> If it's possible to parse JSON with the eXist database, why is the
>>>>>> following code retrieving any data from my JSON document:
>>>>>>
>>>>>> JSON Example.xhtml
>>>>>>
>>>>>> <html xmlns="http://www.w3.org/1999/xhtml">
>>>>>> <head>
>>>>>> <title>First JSON Experiment</title>
>>>>>> <link rel="stylesheet" type="text/css" href="
>>>>>> http://localhost:8080/exist/rest/db/apps/HTML_Student/JSON_Example.css"/>
>>>>>>
>>>>>> <script language="javascript" src="
>>>>>> http://localhost:8080/exist/rest/db/apps/HTML_Student/JSON_Example.js"/>
>>>>>>
>>>>>> </head>
>>>>>> <body onload = "Setup()">
>>>>>> <input type = "text" id = "JSON_Text">
>>>>>> </input>
>>>>>> </body>
>>>>>> </html>
>>>>>>
>>>>>> JSON Example.css
>>>>>>
>>>>>> #JSON_Text {
>>>>>> position: absolute;
>>>>>> top: 200px;
>>>>>> left: 300px;
>>>>>> height: 25px;
>>>>>> width: 300px;
>>>>>> }
>>>>>>
>>>>>> JSON Example.js
>>>>>>
>>>>>> function Setup() {
>>>>>> var XMLHttp;
>>>>>> var JSON_Data;
>>>>>>
>>>>>> XMLHttp = new XMLHttpRequest();
>>>>>>
>>>>>> XMLHttp.onreadystatechange = function () {
>>>>>> if(XMLHttp.readyState == 4){
>>>>>> JSON_Data = JSON.parse(XMLHttp.responseText);
>>>>>> }
>>>>>> };
>>>>>>
>>>>>> XMLHttp.open("Get", "
>>>>>> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json",
>>>>>> true);
>>>>>> XMLHttp.send();
>>>>>>
>>>>>>
>>>>>> document.getElementById("JSON_Text").value = JSON_Data;
>>>>>> }
>>>>>>
>>>>>> People.json
>>>>>>
>>>>>> {
>>>>>> "People":{
>>>>>> {
>>>>>> "name": "Alex",
>>>>>> "online": true
>>>>>> },
>>>>>> {
>>>>>> "name": "Billy",
>>>>>> "online": false
>>>>>> }
>>>>>>
>>>>>> }
>>>>>> }
>>>>>> _______________________________________________
>>>>>> Exist-open mailing list
>>>>>> Exi...@li...
>>>>>> https://lists.sourceforge.net/lists/listinfo/exist-open
>>>>>>
>>>>>
|