Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/check', function (req, res) {
- console.log("Client checking for service...");
- res.writeHead(200, {
- 'Access-Control-Allow-Origin': 'http://localhost',
- 'Content-Length': 0,
- 'Content-Type': 'text/plain'
- });
- res.end();
- console.log("Client checked in!");
- });
- request = $.ajax({
- url: "http://127.0.0.1:8080/check",
- type: "POST",
- crossDomain: true,
- data: '',
- dataType: "json",
- error: function () {
- alert("Could not connect to the server! Returning to login screen.");
- signOut();
- },
- success: function () {
- DoStuff();
- }
- });
- 'Content-Type': 'text/plain'
- dataType: "json"
- <p id="results"></p>
- <button>localpost</button>
- $(function() {
- var localpost = function() {
- var callback = function(name) {
- $("#results").html(name)
- };
- var request = $.ajax({
- type:"POST",
- dataType: "json",
- data: "",
- statusCode : {
- 200: function(data, textStatus, jqxhr) {
- if (textStatus === "success" && jqxhr.responseJSON) {
- alert(textStatus+"n Could not connect to the server! Returning to login screen.");
- alert(JSON.stringify(jqxhr.responseJSON)+"n"
- +String(jqxhr.getResponseHeader("Content-Type")));
- // signOut();
- };
- }
- }
- });
- // `success` callback
- request.done(function(data, textStatus, jqxhr) {
- if (textStatus === "success") {
- // DoStuff()
- callback("textStatus: "
- +textStatus+"<br />jqxhr status: "
- +jqxhr.state()+"<br />content-type: "
- +jqxhr.getResponseHeader("Content-Type")+"<br /><br />"
- +jqxhr.getResponseHeader("Content-Length")+"<br /><br />"
- +jqxhr.getResponseHeader("Access-Control-Allow-Origin")+"<br /><br />"
- +JSON.stringify(data))
- };
- });
- // `error` callback
- request.fail(function(data, textStatus, jqxhr) {
- console.log(textStatus);
- })
- };
- $("button").one("click", localpost);
- // localpost()
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement