我正在尝试开发某种博彩公司的网站解析器,该解析器使用JS(JQuery)上编写的Google Chrome扩展程序从某些div中获取数据,并通过跨域AJAX GET请求将其传递给Sinatra app部署在localhost上。
这是JQuery函数。它可以正常工作并将数据传递到本地https网络服务器。
function refreshScores() {
currentScore = $('.result-description-part').eq(0).html();
firstMatchWinner = $('.foot-market td[data-mutable-id="S1mainRow"] span').html();
secondMatchWinner = $('.foot-market td[data-mutable-id="S2mainRow"] span').html();
$('#currentscore').html(currentScore);
$('#firstmatchwinnercoef').html(firstMatchWinner);
$('#secondmatchwinnercoef').html(secondMatchWinner);
if(firstMatchWinner != prevFirstMatchWinner) {
$.ajax({
type: 'GET',
url: 'https://localhost/coefs',
crossDomain: true,
data: { firstmatchwinnercoef: firstMatchWinner},
success: function () {
}
});
}
prevFirstMatchWinner = firstMatchWinner;
}
setInterval(refreshScores, 500);
}
以下是主要的应用代码
require 'sinatra'
require './sinatra_ssl'
require 'sinatra/cross_origin'
require 'socket'
configure do
enable :cross_origin
end
before do
response.headers["Access-Control-Allow-Origin"] = "*"
end
set :port, 443
set :ssl_certificate, "server.crt"
set :ssl_key, "server.key"
get "/coefs" do
erb :index, :locals => {:firstmatchwinnercoef => params[:firstmatchwinnercoef]}
end
因此,我可以在浏览器中看到博彩公司的网站,并在Ruby命令提示符下看到AJAX正常工作并将数据传递给https://localhost/coefs。但是如何在Sinatra应用程序中显示和操作这些数据?我不想立即将其写入数据库。我应该使用websockets,session还是cookies?什么方法最好?任何帮助将不胜感激,谢谢!