How to post and get javascript document into Database - javascript

I've a web page in which i've inserted a ACE- javascript Code Editor. I want to post javascript code into my database and then retrieve.
for example in case of JSON we use json.stringify and json.parse to post and retrieve data. I'm usieng SAPUI5 backend is in javascript.
var conf = model.getProperty("/automation-rule-body");
Is there any rule to post javascript code into database ?

If your backend supports REST API use create method of sap.ui.model.odata.ODataModel
var oDataModel = sap.ui.model.odata.ODataModel(sServiceUrl, mParameters);
oDataModel.create(sPath, oData, mParameters);

Related

Angular 4 And Node js

In angular 4 at a client side, i have a post method when i click on it ->
var json=JSON.stringify({id:"1",name:"par",title:"ssss"});
var params='json'+json;
this.http.post("http://localhost:3000/users/insertData",params, optio
.subscribe(res => console.log(res.json()));}
after click on this at server side, I am using node express js,
so the problem at server side I am getting data that type which is not acceptable for the database my SQL so data is getting ->
{ 'json{"id":"1","name":"par","title":"ssss"}' : ' ' }
but I want to get data is ->only JSON form
{"id":"1","name":"par","title":"ssss"}
so please give me some solution ...
Try without stringify
var params={id:"1",name:"par",title:"ssss"}
This line: var params='json'+json;
You are concatenating a string with some data in JSON form.
I am not sure what you are trying to do with that, but that is why the data is not JSON when you receive it on the back end.
By default Angular converts all your form submission data into json, even if you submit a model it is converted to json before sending it to the server. Unless you explicitly want to submit form data.
Secondly as pointed out by Adam, what are you trying to achieve using this piece of code var params='json'+json;

Post query from client-side Javascript using Express (node.js)

I'm developing a web app using Express. On one of my pages I have a table filled with data and I want users to be able to modify the data. I use contenteditable (HTML5) to make the data editable (DEMO: http://jsfiddle.net/k854hsae/5/)
I have a Javascript method to submit whatever has been written when the Enter key is pressed:
$(document).ready(function () {
var $editableTd = $('td[contenteditable]');
$editableTd.bind('keyup', function (e) {
if (e.keyCode == 13) {
$(this).blur();
// SAVE NEW DATA TO DATABASE
}
});
});
I use MongoDB. I want to save the new data to the database every time a cell is modified (so no "submit button"). I'm not quite sure on how to pass the information along in Express. From the examples I've seen, they all use Forms with the following syntax in Jade:
form#formAddUser(name="adduser",method="post",action="/adduser")
But I don't know how I can POST using contenteditable. Is there a way to "call" server-side JS from client-side JS?
You can use jQuery .post() method to send ajax post request from client-side JS to server-side JS.

How to pass value to another static page via javascript?

I am trying to pass value to another page and read the value in the another page. I use only JavaScript and jQuery. Not use others language as PHP. I don't want to be as like (http://www.example.com/?value=test). I am trying to use POST or GET method.
On first page:
$.post("second_page.html",{q:"test"});
window.location.replace("second_page.html");
On second page:
var location_query = window.location.search.substring(1);
var vars = location_query.split("&");
for (var i in vars) {
var param = vars[i].split("=");
params[param[0].toString()] = param[1];
}
If I pass value as like http://www.example.com/?q=test , the second page script is read the value, but I use this line: $.post("second.html",{q:"test"}); not read.
How to pass value from first page to another static page via JavaScript or jQuery or ajax?
See this post says:
POST data is data that is handled server side. And Javascript is on client side. So there is no way you can read a post data using JavaScript.
but you can use cookies to read and store values:
<script src="/path/to/jquery.cookie.js"></script>
you can get it from here
Try with reading the documentation and see if this works for you.
Without using GET or POST you can transfer the content using HTML5 Local Storage or
Web SQL
$.post and $.get send AJAX request and waiting response on current page, you cant send params for next window.location.replace by this.
Use url get-params window.location.replace("404.html?q=404"); and look this for get params on second page.

RESTful version of common Ajax request

I've used this "good old" way to fetch HTML formatted data via Ajax and inject it into the DOM.
http://localhost/ajax-controller/mobile-view/resource/1/
$mobile_view = new View('mobile-view'); // use mobile view
$mobile_view->data = $this->data_array; // add some data to view
$this->response->body($mobile_view); // return formatted HTML
http://localhost/ajax-controller/web-view/resource/1/
$web_view = new View('web-view'); // use normal web view
$web_view->data = $this->data_array; // add some data to view
$this->response->body($web_view); // return formatted HTML
Question is What is the RESTful version of this?
Should I fetch just JSON data via Ajax?
http://localhost/ajax-controller/resource/1/
$this->response->body(json_encode($this->data_array)); // return JSON data
How should I handle view / HTML formatting, another ajax request? Or am I missing something?
it is fine to have views in restful services, as determining how to return data. I would suggest passing a url parameter like
http://localhost/ajax-controller/resource/1/?view=mobile
and figuring out how to respond via that parameter

Retrieving JSON with JQuery

I'm trying to retrieve JSON with JQuery from: http://www.chirpradio.org/json
How do I retrieve, parse and display that JSON in a web page.
I'm new to JSON and JQuery, and the onsite documentation is a bit difficult to follow.
Thanks,
Moemonty
One way to get past the SOP is to use a proxy(which also converts it into JSONP). i.e.:
var url = "http://www.chirpradio.org/json";
jQuery.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22"+url+"%22&format=json&callback=?", function(data){
console.log(data.query.results.json);/*where yahoo puts the json object*/
});
However, I suggest not to query w/sensitive information(it's insecure). Your use with the radio feed is ok though.

Categories

Resources