ajax - How to post to external url from rails app without using form -


i able post payment gateway using html form. got new requirement. now, on click of "payment" button, have validate whether item still available purchase , if available automatically post payment form gateway.

so say, want execute rails controller code on button click , want redirect external url ( payment gateway ) params if validation succeed.

i read, not possible post using redirect_to in rails. not possible post using ajax external url. how should achieve ?

you can use ruby’s net::http this:

require "net/http" require "uri"  uri = uri.parse("http://example.com/search") params = {"foo" => "value one", "bar" => "value two"}   # shortcut way response = net::http.post_form(uri, params)   # more control http = net::http.new(uri.host, uri.port) request = net::http::post.new(uri.request_uri) request.set_form_data(params) response = http.request(request)   puts response.code             # => 200 puts response.body             # => body (html, json, etc) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -