Page 1 of 1
SB70LC: web server, AJAX
Posted: Wed Jul 06, 2016 4:18 am
by xianghe
Hello,
I'm working on the NB web server, I know there is network programing guide talk about this, and the key is the callback function mechanism, it's useful to the 'submit' HTML.
But now web page using Javascript AJAX, there is no 'submit' button, can you tell me how to develop the web server?
Re: SB70LC: web server, AJAX
Posted: Wed Jul 06, 2016 10:20 am
by rnixon
I don't think there is anything netburner specific on this. It is web programming. Doing a quick search on "submit form in javascript" I found there is a javascript submit function:
http://www.w3schools.com/jsref/met_form_submit.asp. I do not know much about javascript, but my guess would be that it generates a POST just like an HTML form.
Re: SB70LC: web server, AJAX
Posted: Thu Jul 07, 2016 1:21 am
by xianghe
...I found there is a key function,
Code: Select all
function ajaxSend(reqtype, url, senddata, callback)
{
var ajaxRequest = null;
var ajaxCallback;
ajaxRequest = new XMLHttpRequest();
if(ajaxRequest)
{
ajaxRequest.open(reqtype, url, true);
if(callback)
{
ajaxRequest.onload = function()
{
var jsonData = JSON.parse(this.responseText);
ajaxCallback(jsonData);
}
}
}
if(reqtype === "POST")
{
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencode");
}
if(reqtype === "GET")
{
ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
}
ajaxRequest.send(senddata);
There is no 'submit', here is ajaxRequest.send().
Re: SB70LC: web server, AJAX
Posted: Thu Jul 07, 2016 8:54 am
by ecasey
That Ajax function should send a "get" or "post" request to the url of the SB70. You will have to write a custom get-handler or post-handler to extract the data. Look at the Web examples, there is one called FlashForm that might be helpful.