I have code that use JQuery to call services module and login. After Login, I call token through ?q=services/session/token and gets the token of the user. I think that i have got the right token... After that the code calle to ?q=my_services_endpoint/system/connect.json and pass through the header the token.
the problem is that i get those lines in the console and no success of course...
7dR8Eo0pmiTeMCHLUeneAAQFCONn80NgXnJuNqhrtYw login.js:38
OPTIONS http://{localhost}:8888/drupal2/?q=system/connect.json 404 (Not Found) jquery-1.6.4.min.js:4 POST
POST http://{localhost}:8888/drupal2/?q=system/connect.json 404 (Not Found)
this is the code:
$.ajax({
url: "http://{localhost}:8888/drupal2/?q=test_test/user/login.json",
type: 'post',
data: 'username=' + encodeURIComponent(name) + '&password=' + encodeURIComponent(pass),
dataType: 'json',
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('page_login_submit - failed to login');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function(data) {
$.cookie("sessid", data.sessid);
$.cookie("session_name", data.sessid);
// Obtain session token.
$.ajax({
url: "http://{localhost}:8888/drupal2/?q=services/session/token",
type: "get",
dataType: "text",
error: function(jqXHR, textStatus, errorThrown) {
alert("Didn't got the token");
},
success: function(token) {
console.log($.cookie("sessid"));
console.log(token);
// Call system connect with session token.
$.ajax({
url: 'http://{localhost}:8888/drupal2/?q=test_test/system/connect.json',
type: "post",
dataType: "json",
beforeSend: function(request) {
request.setRequestHeader("X-CSRF-Token", token);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
},
success: function(data) {
alert('Hello user #' + data.user.uid);
}
});
}
});