Reputation: 71
I try to send GET method with ajax in jquery, It has a problem when the data has specific string or character.
I want to send full uri path in jquery querysting.
I tried to URIEncode or URIDecode blah blah blah, but It really doesn't work.
my jsp file
====================================================================================
$("#kakaoLogin").click(function() {
var loginPage = "${login_page}";
var urlStr = encodeURI("${login_page}");
console.log(loginPage);
console.log(urlStr);
$.ajax({
url: "${request_url}",
data: {
client_id : "${client_id}",
login_page : loginPage, // problem line
response_type : "${response_type}"
},
method: "GET",
dataType: "json"
});
result with my google devtool console
(index):20 http://localhost:8000/login
(index):21 http://localhost:8000/login
jquery.min.js:5 GET https://kauth.kakao.com/oauth/token?client_id=a4166bb…&login_page=http%3A%2F%2Flocalhost%3A8000%2Flogin&response_type=code 400 (Bad Request)
how to fix damn it?
Upvotes: 0
Views: 57
Reputation: 2589
I doubt this actually has anything to do with querystring encoding. Slashes are supposed to be encoded/escaped in a querystring, so you should want the current behavior to continue, not change. If you check out the redirect path that is used in one of the official demos, they fully encode query string.
A) This doesn't seem like the right endpoint (you are trying to make a GET to a POST endpoint for refreshing tokens). The endpoint for trying to login and obtain the user token is GET /oauth/authorize
. See here.
B) Even if this was the right endpoint, that should be redirect_uri
, not login_page
C) If you are indeed trying to authorize a user for the first time, the OAuth flow is going to require that the login url (/oauth/authorize?client_id={app_key}&redirect_uri={redirect_uri}&response_type=code
) actually be opened in a new tab or popup window, since if the user is not logged into Kakao, it needs to redirect them to the login page before an auth token can be approved / created. You can see this functionality on this demo page.
I would highly recommend reading through the REST API docs, here, and/or checking out their JS SDK - it simplifies the auth process greatly and can create a login button with just a few lines of code.
Upvotes: 1