you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (9 children)

Use the fetch API, you are right that xmlhttp is obsolete.

const json = JSON.stringify(obj);

const res = await fetch('http://127.0.0.1:8000/register', 
{
  method: "post",
  headers: 
  {
    "Content-Type": "application/json",
  },
  body: json,
})

[–]jingles[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (8 children)

ok, i really appreciate that, mr hongkongphooey..

but that code doesnt really make sense.

for example, the "Content-type: text/html\r\n\r\n" is part of the response that is returned from the web server... it has nothing to do with the request, just fyi... unless you would care to enlighten me..

just fyi, you can go to a shell and type "telnet google.com 80" and then type "GET / HTTP/1.0\n\n" and the web server will return your website html and javascript which will begin with a "Content-type: text/html\n\n"

anyways, my webserver is working now... but i need to clean it up a bit..

and i now need to get my code in place that will allow my browser to make regular website requests using either xmlhttprequest or fetch...

i am actually expecting that xmlhttprequest is going to be fine and i can really believe that they will actually put that code obsolete and non functioning... i am guessing that there are way too many applications that use that xmlhttprequest to put it compeltely out of commission.

i will keep you posted.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (7 children)

for example, the "Content-type: text/html\r\n\r\n" is part of the response that is returned from the web server... it has nothing to do with the request, just fyi... unless you would care to enlighten me.

That particular example is sending the registration form fields as JSON in the body of the request. JSON is the most common format to send data between the client and server when you have javascript to deal with.

Fetch should be faster than XHR most of the time because it decodes JSON off thread being promise based. XHR will work fine, it's still supported in browsers, but fetch is a better performing API

[–]jingles[S] 1 insightful - 2 fun1 insightful - 1 fun2 insightful - 2 fun -  (6 children)

i dont need json... i am old school... my preference is similar to how data is received in an http response, "variablename: value"

i am quite happy with something like that.. i just want to be able to request a webpage and to receive it;s header and body.

can you point me to how to do that? if it is the lowest possible level way to do it, i am all the happier.

fuck json.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (5 children)

Sure, fetch is pretty easy to work with actually

The simplest example is just:

const response = await fetch('http://127.0.0.1:8000/some_path')

This will request whatever you are serving at that address, and the entire HTTP response is stored in the variable with accessible fields.

You can access the header and body and whatver else you need through the response object

if(response.status === 200)
{
  console.log(response.body)
}
else
{
  alert("My penis hurts!")
}

or however you want to handle the response

[–]jingles[S] 1 insightful - 2 fun1 insightful - 1 fun2 insightful - 2 fun -  (4 children)

//does a semicolon go on the end of this line? or not?
const response = await fetch('http://127.0.0.1:8000/some_path')

if(response.status === 200)
navigate("/some_other_route", { replace: true }); 
else
alert("My penis hurts!");

//again, i guess that no semicolon goes here? like in C?
console.log(response.body)

does the above look right?

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (3 children)

Javascript you can do it either way, but you do not need the semicolons, that looks right except for the lack of curly braces after the 'if' statement, i'm not sure if javascript lets you leave them out for 1 liners, but it probably does

[–]jingles[S] 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (2 children)

i am so comfortable in C language.. my first C compiler was the microsoft quickC for dos, i bought it in 1991 from egghead software for $70.00

i have done a little bit of reading about javascript and i get the hint that javascript was sortof slapped together and some of it is held together with duct tape. that is my impression after reading it.

omg i wish that i could embed C straight into a fucking browser.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (1 child)

i have done a little bit of reading about javascript and i get the hint that javascript was sortof slapped together and some of it is held together with duct tape. that is my impression after reading it.

Yes, I feel the same way about javascript, its terrible, especially if you are used to a real systems language like C

omg i wish that i could embed C straight into a fucking browser.

Technically you can...C can compile to WASM, but I'm not sure how mature that ecosystem is for C in terms of the WASM bindings

[–]jingles[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (0 children)

i looked at web assembly.. nah.

anyways, i just want to find a super basic way to read an html header and body... i think that you just gave it to me a few posts back..

gonna get some rest and go at it again.

truth is, my health is not good, and you know.. my future aint bright.. but i used to really like coding.

truth is that i am subject to walking off the edge of this planet any time now.

but thanks for your kind inputs.

edward scissorhands.