javascript - jquery ajax https call gives ERR_INSECURE_RESPONSE -



javascript - jquery ajax https call gives ERR_INSECURE_RESPONSE -

i'm trying create https cors ajax phone call jquery node.js process. when ever phone call made chrome complains in console options https://localhost/ net::err_insecure_response.

looking @ similar stack overflow question, cross domain request http https aborts immediately should able create cross origin https ajax calls if import self signed cert made. imported cert chrome. can see certificate in chrome's manage certificates tab under authorities. still fails when seek ajax call.

this how made private key: openssl genrsa -out domain.key 4096

now cert: openssl req -x509 -sha512 -nodes -newkey rsa:4096 -keyout domain.key -out domain.crt

for mutual name set ip address of computer chrome not complain url mismatch.

here html page.

<!doctype html> <html> <title>blackbox</title> <head> <meta charset="utf-8"> <script src="jquery-1.11.2.min.js"></script> <script src="bootstrap-3.3.4-dist/js/bootstrap.min.js"></script> <script src="login.js"></script> </head> <body> <div class="container-fluid"> <div class="row"> <div class=col-md-4> <h2> welcome blackbox</h2> <label>username</label> <input type="text" name="username" id="username"> <label>password</label> <input type ="text" name="password" id="password"> <input type="button" id="loginbtn" value="login"/> <div class="container"> <div class="row"> <div class="out"></div> </div> </div> </div> </div> </div> </body> </html>

this javascript goes along html.

$(document).ready(function() { $('#loginbtn').click(clicklogin); function clicklogin() { var username = $('#username').val(); var password = $('#password').val(); if(password == '' || username == '') { $(".out").html("empty username or password"); } else { $.ajax({ type: "put", url: "https://localhost/", contenttype: "application/json", data: json.stringify({ username: username, password: password, }), datatype: "text", }) } }; });

and here node process both serves html , javascript , suppose receive ajax calls.

const fs = require("fs"); const http = require('http'); const https = require('https'); var loginpage = fs.readfilesync('login.html'); var loginpagejs = fs.readfilesync('login.js'); var jquery = fs.readfilesync('jquery-1.11.2.js'); var bootstrap = fs.readfilesync('bootstrap-3.3.4-dist/js/bootstrap.min.js') var options = { key: fs.readfilesync('domain.key'), cert: fs.readfilesync('domain.crt') }; http.createserver(function(req, res) { res.writehead(301, {location: 'https:192.168.1.58/'}) res.end(); }).listen(80); https.createserver(options, function(req, res) { if(req.method === 'get' && req.url === '/') { res.writehead(200, "ok", {'content-type': 'text/html'}); res.write(loginpage); res.end(); } else if(req.method === 'get' && req.url === '/login.js') { res.writehead(200, "ok", {'content-type': 'application/javascript'}); res.write(loginpagejs); res.end(); } else if(req.method === 'get' && req.url === '/jquery-1.11.2.js') { res.writehead(200, "ok", {'content-type': 'application/javascript'}); res.write(jquery); res.end(); } else if(req.method === 'get' && req.url === '/bootstrap-3.3.4- dist/js/bootstrap.min.js') { res.writehead(200, "ok", {'content-type': 'application/javascript'}); res.write(bootstrap); res.end(); } else if(req.method === "options" && req.url === '/') { res.writehead(204, "no content", { "access-control-allow-origin": origin, "access-control-allow-methods": "get, post, put, delete, options", "access-control-allow-headers": "content-type, accept", "access-control-max-age": 10, "content-length": 0 }); var requestbodybuffer = []; req.on("data", function(chunk) { requestbodybuffer.push(chunk); }) req.on("end", function() { var requestbody = requestbodybuffer.join(""); var obj = json.parse(requestbody); if(obj.hasownproperty('username') && obj.hasownproperty('password')) { console.log(obj.username); console.log(obj.password); } }) } }).listen(443);

javascript jquery ajax node.js ssl

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -