you are viewing a single comment's thread.

view the rest of the comments →

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

a webpage can only do dynamic processing by using javascript or by using some other programming thing that executes inside of the browser.

you CAN NOT produce a dynamic chat by using server side code alone.

period.

check around.

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

Yes, I realize you can't do chat like that, but you could do all of the other saidit features like loggin in, posting and commenting without a single line of JS

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

right now, i need to know how to produce a dynamically live web app... kinda like what i would use to produce a live TRADING CHART with dynamically changing prices, etc.. and a dynamic chart...

i basically know how to do this.. i just need to find the most low level way wth javascript.. i think i want to use either xmlhttprequest or fetch.. i am nto sure which.. i am reading that xmlhttprequest may be obsolete.. so i want to be careful to not select a programming method that will become deprecated later..

[–][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] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (0 children)

i really like the idea of running a mice site on the darkweb.

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

technically, even a forum should be dynamic.. it should update its page without refreshing.