简体   繁体   中英

AJAX Query into Rails with HTTParty

I'm working with a pseudo API. I got a sample AJAX call from the developers, and am working to convert it into Ruby with HTTParty to make a call from an object.

AJAX:

$.ajax({
        dataType: "jsonp",
        crossDomain: true,
        jsonpCallback: "DataCallBack",
        url: "http://servicedomain.com/Widgets/Quotes.ashx",
        data: { partnerID: '39' }
     })

As of right now, my call looks like this:

query = {
  'dataType' => "jsonp",
  'crossDomain' => true,
  'jsonpCallback' => "DataCallBack",
  'url' => "http://servicedomain.com/Widgets/Quotes.ashx",
  'data' =>  { 'partnerID' => '39' }
}

HTTParty.post("http://servicedomain.com/Widgets/Quotes.ashx", :body => query)

The response is a web page that says the URL isn't valid. Is my syntax right?

It's a GET request:

query = { 'partnerID' => '39' }

HTTParty.get("http://servicedomain.com/Widgets/Quotes.ashx", :query => query)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM