Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access POST data sent from a browser to Rikulo Steam Server
    primarykey
    data
    text
    <p>I ask the browser to POST JSON data to the stream v0.5.5 server using ajax. In the server side, how can I receive the data from the ajax request?</p> <p>My client:(Google Chrome)</p> <pre><code>void ajaxSendJSON() { HttpRequest request = new HttpRequest(); // create a new XHR // add an event handler that is called when the request finishes request.onReadyStateChange.listen((_) { if (request.readyState == HttpRequest.DONE &amp;&amp; (request.status == 200 || request.status == 0)) { // data saved OK. print(request.responseText); // output the response from the server } }); // POST the data to the server var url = "/news"; request.open("POST", url, true); request.setRequestHeader("Content-Type", "application/json"); request.send(mapTOJSON()); // perform the async POST } String mapTOJSON() { print('mapping json...'); var obj = new Map(); obj['title'] = usrTitle.value == null ? "none" : usrTitle.value; obj['description'] = usrDesc.value == null ? "none" : usrDesc.value; obj['photo'] = usrPhoto.value == "none"; obj['time'] = usrTime==null ? "none" : usrTime.value; obj['ip']= '191.23.3.1'; //obj["ip"] = usrTime==null? "none":usrTime; print('sending json to server...'); return Json.stringify(obj); // convert map to String i.e. JSON //return obj; } </code></pre> <p>My server:</p> <pre><code>void serverInfo(HttpConnect connect) { var request = connect.request; var response = connect.response; if(request.uri.path == '/news' &amp;&amp; request.method == 'POST') { response.addString('welcome from the server!'); response.addString('Content Length: '); response.addString(request.contentLength.toString()); } else { response.addString('Not found'); response.statusCode = HttpStatus.NOT_FOUND; } connect.close(); } </code></pre> <p>Again, I don't want the browser to ask for data from the server! What am I doing is to asking the browser to submit the JSON data via ajax, and I just don't know how the server (Rikulo Stream v0.5.5) gets the "content" of data? All code is written in Google Dart Language M3. No Javascript!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload