/ / jquery ajax в nodejs не може отримати / розмістити за допомогою https - jquery, ajax, node.js, https

jquery ajax в nodejs не може отримати / post з https - jquery, ajax, node.js, https

    var app, express, fs, jquery, jsdom;

jsdom = require("jsdom");

fs = require("fs");

express = require("express");

jquery = fs.readFileSync("./jquery-2.0.3.min.js").toString();

jsdom.env({
html: "<html></html>",
src: [jquery],
done: function(errors, window) {
var $;
$ = window.$;
window.print = console.log;
console.log(errors);
return $.ajax({
url: "https://www.baidu.com",
type: "GET",
error: function(jqXHR, textStatus, errorThrown) {
return print(jqXHR.url + " " + jqXHR.status + " " + " " + textStatus + " " + errorThrown);
},
success: function(data, textStatus, jqXHR) {
return console.log(data);
}
});
}
});

app = express();

app.listen("3000", function() {});

Я збираюся перенести проект на nodejs. Він використовує jquery ajax для обміну інформацією про протокол https.

наведена вище демо відповідь:

location.replace(location.href.replace("https://","http://"));

як я можу зробити виклик https у nodejs & jquery ajax

ps: Я не можу отримати будь-який пакет від скрипця, якщо я використовую nodejs + jquery ajax

Відповіді:

0 для відповіді № 1

Хоча я впевнений, що для цього можна використовувати jQuery та jsDom, для цього існує набагато більше перевірених і справжніх бібліотек. Наприклад, багато розробників вузлів використовують бібліотека requestjs

Так замість того

$.ajax({
url: "https://www.baidu.com",
type: "GET",
error: function(jqXHR, textStatus, errorThrown) {
return print(jqXHR.url + " " + jqXHR.status + " " + " " + textStatus + " " + errorThrown);
},
success: function(data, textStatus, jqXHR) {
return console.log(data);
}
});

Ви б робили:

request(
uri: "https://www.baidu.com",
method: "GET",
function(err, res, body){
// handle the err and do what you want with the response
});