A. L.
A. L.

Reputation: 73

Ajax Post request example

I was wondering if anyone could help me with a simple ajax request example just so I can wrap my head around the whole idea. I tried testing an ajax request to search the word "rails" on github. So my code looks something like this:

$.ajax({
url: 'www.github.com',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
data: {
    q: 'rails'
},
success: function(data) {
    console.log(data);
}

});

This request is responding with a 404 response. So, I'm just curious how are you supposed to know what the key names for the "data" element should be? When I inspected the search bar on github, it told me the name of the element was q. Hence why I used the key "q" and I wanted to search for say "rails". If anyone could help me with this example or perhaps provide a better one that would be greatly appreciated. Thanks!

Upvotes: 0

Views: 1266

Answers (1)

Kevin Grosgojat
Kevin Grosgojat

Reputation: 1379

Try to add http in your url, but, for security reason you can't do Ajax Crossdomain request without autorisation of the github.com domain in your case.

http://api.jquery.com/jquery.ajax/

Upvotes: 2

Related Questions