1

I'm building a web application that interfaces with another department's search site. The idea is that the user will begin to type a term they wish to search for on our website - for instance, "bread". They'll get an AJAX-y, autocomplete list of all the possible terms from this other department's site that include "bread". After selecting a term, they'll be redirected to http://other-site.com/, and the results from searching for their selected term will be displayed.

The issue is that I can't simply redirect to http://other-site.com/?term={whatever-term-they-selected}. According to the API specs I've been given, I have to redirect the user to the root URL, http://other-site.com/, with some meta-data about the search term as JSON in the request body. Is this even possible? I can redirect the user to http://other-site.com/ via a header, but that won't include the data in the request body. I can submit a form pointing to http://other-site.com/, but then the body won't be raw JSON - it'll be form data.

I think I need to ask the other department to change their API, but I want to make sure of this before I do.

rybosome
  • 4,974
  • 6
  • 40
  • 64
  • "A GET request with JSON in the body" - does not make sense, only POST is supposed to contain a request body. – Lekensteyn May 14 '12 at 19:04

3 Answers3

0

Usually a GET request has no body, so try with a POST.

Further infos here: GET with body

Community
  • 1
  • 1
Wilk
  • 6,287
  • 8
  • 45
  • 65
0

May be this will help you http://skypher.com/wiki/index.php/Programming/JavaScript/serialize%28%29

Or may be this question Best way to pass JSON from Browser to PHP using Ajax.Request

Community
  • 1
  • 1
Imdad
  • 5,695
  • 4
  • 31
  • 53
0

To answer the question - no, it is not possible for a browser to issue and follow a GET request to another domain with a JSON-body. The other site had to change their API.

rybosome
  • 4,974
  • 6
  • 40
  • 64