0

I am trying to make a post to the Google Custom Search URL GET https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures

from my Twitter Boostrap (V3) enabled UI. Here is the code

 <form class="navbar-form navbar-left" role="search" method="get" action="https://www.googleapis.com/customsearch/v1?key=xxxx&cx=xxx:xxx">
            <div class="form-group">
                <input type="text" id='q' class="form-control" placeholder="Search">
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
        </form>

However I get the following error

{
  "error": {
  "errors": [
              {
                "domain": "global",
                "reason": "required",
                "message": "Required parameter: q",
                "locationType": "parameter",
                "location": "q"
         }
           ],
                "code": 400,
                "message": "Required parameter: q"
         }
       }
1
  • Please state a question. Also note that the action in your code has no query parameter - so it is not surprising that you get that error msg. Commented Apr 2, 2014 at 20:06

1 Answer 1

0

You need to add onsubmit event handler to form and make URL request to google search with adding the query parameter to it, something like following

Your form-

 <form class="navbar-form navbar-left" role="search" onsumit='submitMyForm'>

and in script tag (assuming you are using jquery)

<scirpt>
function submitMyForm(){

  // get query parameter
 query= $('#q').val()
 // form request URL
 reqUrl = 'https://www.googleapis.com/customsearch/v1?key=xxxx&cx=xxx:xxx&q='+query

// make ajax get request 
$.get(
    reqUrl,
    function(data) { 
    // data contains the search results
 },
);

}
</scirpt>
`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.