You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//a button is placed down; similar in HTMLbutton(type='button',id='send_by_button')Modifydata
#modify LoremipsumSender//loading jQuery; it can be done from an online source as wellscript(src='./js/jquery-2.2.0.min.js')//AJAX request using jQueryscript$(function(){$('#send_by_button').click(function(e){e.preventDefault();//test: the text within brackets should appear when clicking on said button//window.alert('You clicked on me. - jQuery');//a variable and a JSON initialized in the codevarpredeclared="Katamori";vardata={Title: "Name_SenderTest",Nick: predeclared,FirstName: "Morol",Surname: "Schmidt"};//an AJAX request with given parameters$.ajax({type: 'POST',data: JSON.stringify(data),contentType: 'application/json',url: 'http://localhost:7776/domaintest',//on success, received data is used as 'data' function inputsuccess: function(data){window.alert('Request sent; data received.');varjsonstr=JSON.stringify(data);varjsonobj=JSON.parse(jsonstr);if(data.Nick!=predeclared){document.getElementById("modify").innerHTML="JSON changed!\n"+jsonstr;};}});});});
domaintest_route.js
varexpress=require('express');varrouter=express.Router();router.get('/',function(req,res,next){});//same for POST requests - notice, how the AJAX request above was defined as POSTrouter.post('/',function(req,res){res.setHeader('Content-Type','application/json');//content generated herevarsome_json={Title: "Test",Item: "Crate"};varresult=JSON.stringify(some_json);//content got 'client.jade'varsent_data=req.body;sent_data.Nick="ttony33";res.send(sent_data);});module.exports=router;