title: How do I set a Sinatra session from JQuery?
body: <p>I am trying to create a session from JQuery to my Sinatra backend. When I send a POST request outside of Ajax, using something like POSTman, I am able to set a session, but when I send via JQuery, I just get NULL in return. How do I create a session using AJAX?Should I be actually doing this via AJAX or should I jus have a login screen?</p>
  
  <p>This is my session (and some other pertinent) setting code:</p>
  
  <pre><code>set :protection, :except =&gt; [:http_origin, :remote_token] //I put this because Sinatra was denying the request before
  set :session_secret, "My session secret"
  
  post '/session' do
      session[:user_id] ||= 'hihiiddasdah'
      session[:user_id].to_json
  end
  
  delete '/session' do
      session.clear
      session[:user_id].to_json
  
  end
  
  get '/session' do
      session[:user_id].to_json
  end
  </code></pre>
  
  <p>and this is my JQuery code for getting the session:</p>
  
  <pre><code>$.post(URL + 'session', {function(data) {console.log(data);});
  </code></pre>