Re: Can you parse JSON with the eXist database?
Ted Hickox <[email protected]> Mon, 19 Aug 2024 17:02:50 -0500
| Newsgroups | gmane.text.xml.exist |
|---|---|
| Message-ID | <CAAsp6CYmwxK1vbeC6viedKDS4T-ymH6zSWc6ujo_8X_yq9wUGg@mail.gmail.com> |
In case you were wondering how I fixed my project, I will give you the
details.
I borrowed some code from my SVG_Bezier_Curve Javascript page:
function Setup2() {
var SVG_Data;
var Retrieved_Data;
var Bezier_Curve_1;
var Bezier_Curve_2;
var Counter;
var Coordinate_Attribute;
var Coordinate;
var Style_Attribute;
var Style_Details;
var Bezier_Curve_Identification;
SVG_Data = new XMLHttpRequest();
SVG_Data.open("GET","
http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve.xq",
true);
SVG_Data.onreadystatechange = function () {
if (SVG_Data.readyState == 4) {
Retrieved_Data = SVG_Data.responseText;
Retrieved_Data = Retrieved_Data.split("/");
Counter = 0;
Bezier_Curve_1 = Retrieved_Data[Counter];
Counter = Counter + 1;
Bezier_Curve_2 = Retrieved_Data[Counter];}
Bezier_Curve_1 = Bezier_Curve_1.split("*");
Counter = 0;
Coordinate_Attribute = Bezier_Curve_1[Counter];
Counter = Counter + 1;
Coordinate = Bezier_Curve_1[Counter];
Counter = Counter + 1;
Style_Attribute = Bezier_Curve_1[Counter];
Counter = Counter + 1;
Style_Details = Bezier_Curve_1[Counter];
Bezier_Curve_Identification =
document.getElementById('Bezier_Curve_1');
Bezier_Curve_Identification.setAttribute(Coordinate_Attribute, Coordinate);
Bezier_Curve_Identification.setAttribute(Style_Attribute,
Style_Details);
Bezier_Curve_2 = Bezier_Curve_2.split("*");
Counter = 0;
Coordinate_Attribute = Bezier_Curve_2[Counter];
Counter = Counter + 1;
Coordinate = Bezier_Curve_2[Counter];
Counter = Counter + 1;
Style_Attribute = Bezier_Curve_2[Counter];
Counter = Counter + 1;
Style_Details = Bezier_Curve_2[Counter];
Bezier_Curve_Identification =
document.getElementById('Bezier_Curve_2');
Bezier_Curve_Identification.setAttribute(Coordinate_Attribute, Coordinate);
Bezier_Curve_Identification.setAttribute(Style_Attribute,
Style_Details);
};
SVG_Data.send();}
I changed some variable names and a couple of other minor things and
developed this code:
function Setup() {
var XMLHttp;
var JSON_Data;
var Retrieved_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) {
Retrieved_Data = XMLHttp.responseText;
document.getElementById("JSON_Text").value = Retrieved_Data}
};
XMLHttp.send();}
I also turned off a feature in the console because the CTRL F5 wasn't
working correctly. When I finish my current project, I will publish a
video of my work on YouTube for everyone to watch. I don't want anyone to
be as stuck as I was today. It's hard when you don't know what you're
doing wrong and everything you try to do doesn't change anything.
On Mon, Aug 19, 2024 at 3:11 PM Ted Hickox <[email protected]> wrote:
> If I knew as much as all of you know, I wouldn't be asking you for
> assistance. But I'm over 50 years old and I used to program on an NCR
> mainframe using COBOL. So you might say I was at the foundation of
> computers.
>
> My first problem is that the CTRL F5 doesn't always refresh my webpage.
> So this presents a challenge. And at the beginning of this interaction I
> showed everyone my HTML, CSS, Javascript, and JSON pages. but I can only
> presume that the people who have participated in this conversation so far
> have not read my original post. So once again I will post my code.,
>
> My HTML page:
>
> <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_2.js"/>
> </head>
> <body onload="Setup()">
> <input type="text" id="JSON_Text">
> </input>
> </body>
> </html>
>
> My CSS page:
>
> #JSON_Text {
> position: absolute;
> top: 200px;
> left: 300px;
> height: 25px;
> width: 300px;
> }
>
> My current Javascript page:
>
> function Setup() {
> var XMLHttp;
> var JSON_Data;
>
> MLHttp = new XMLHttpRequest();
> XMLHttp.open("GET", "
> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json", true);
> XMLHttp.send();
> }
>
> And my current JSON page:
>
> {"name":"John", "age":30, "city":"New York"}
>
> And my most recent error:
>
> [image: image.png]
>
> Up until now the console hasn't been displaying any errors. So how could
> I correct something that I couldn't identify?
>
> On Mon, Aug 19, 2024 at 2:47 PM Florian Schmitt <
> [email protected]> wrote:
>
>> Ted, since nobody here knows how your complete code and db content looks
>> like, you'll have to fix it yourself. To do so, check how to use the Web
>> Console:
>>
>> For Firefox, see
>> https://firefox-source-docs.mozilla.org/devtools-user/web_console/index.html
>> For Edge, see
>> https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/console/
>> For Chrome, see
>> https://developer.chrome.com/docs/devtools/console?hl=en#javascript
>>
>> and test what happens if you enter the three commands from your js:
>>
>> XMLHttp = new XMLHttpRequest();
>> XMLHttp.open("GET", "
>> http://localhost:8080/exist/rest/db/apps/HTML_Student/people.json",
>> true);
>> XMLHttp.send();
>>
>> in the Web Console.
>>
>>
>>
_______________________________________________
Exist-open mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/exist-open
image.png
(image/png, 31.9 KB) - not displayed