2017-08-08 1 views
-2

J'essaie de me connecter à la page avec Oracle Jet, en utilisant le gestionnaire de paquets ypmeman npm avec des outils de construction grunt. réponse d'erreur ci-dessous jeté du serveur:Erreur de gestion: HttpRequestMethodNotSupportedException lors de la tentative de connexion

o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: HttpRequestMethodNotSupportedException, Request method 'GET' not supported.

Mais je suis en utilisant la méthode POST Ajax.

define(['ojs/ojcore','knockout', 'ojs/ojinputtext', 'ojs/ojbutton', 
'ojs/ojknockout-validation', 'ojs/ojmodel' 
], function (oj, ko) { 
/** 
* The view model for the main content view template 
*/ 
function logintestContentViewModel() { 
    var self = this; 
    self.tracker = ko.observable(); 
    self.username = ko.observable(""); 
    self.password = ko.observable(""); 
    self.clickedButton = ko.observable(); 
    self.buttonClick = function(data, event) 
    { 
     //alert("call"+JSON.stringify(data)); 
     var trackerObj = ko.utils.unwrapObservable(self.tracker); 


     alert("submittedValue====="+self.username()); 
     alert("password====="+self.password()); 
     //self.submittedValue(); 
     //change this to a valid ajax call. 
     alert("ajax call initiated"); 


     self.url = "http://192.168.0.100:8080/oauth/token?grant_type=password"; 
     self.url +="&username="; 
     self.url += self.username(); 
     self.url +="&password="; 
     self.url += self.password(); 
     //this.url += "client_id=my-trusted-client&client_secret=clientpassword"; 
     $.ajax({ 

      url: self.url, 
      type: "POST", 
      grant_type : "password", 
      data: {client_id : "my-trusted-client", client_secret: "clientpassword1"}, 
      dataType: 'json', 
      success: function(res) { 
       alert(res); 
       this.submittedValue(res.token); 
      }, 
      failure: function(jqXHR, textStatus, errorThrown) { 
       console.log(textStatus); 
       this.submittedValue("Login Failed"); 
      } 
     }) 
     //this.submittedValue(this.url) 
     return true; 

     /* 
     $.ajax({ 
      type: "POST", 
      dataType: "jsonp", 
      crossDomain:true, 
      data: "grant_type=password&username="+self.username()+"&password="+self.password()+"", 
      xhrFields: { 
       withCredentials: true 
      }, 
      beforeSend: function (xhr) { 
       xhr.setRequestHeader('Authorization', 'Basic bXktdHJ1c3RlZC1jbGllbnQ6Y2xpZW50cGFzc3dvcmQ='); 
      }, 
      url: 'http://192.168.0.100:8080/oauth/token', 
      success: function(data) { 
       alert(data); 
      } 
     });*/ 

    }; 




    self.routePage = function(data,event) 
    { 
     self.clickedButton(event.currentTarget.id); 
     return true; 
    }; 
    self.onClick = function() 
    { 
     self.buttonClick(); 
     self.routePage(); 
    } 
    self.shouldDisableCreate = function() 
    { 
     var trackerObj = ko.utils.unwrapObservable(self.tracker), 
     hasInvalidComponents = trackerObj ? trackerObj["invalidShown"] : false; 
     return hasInvalidComponents; 
    }; 
    self._showComponentValidationErrors = function (trackerObj) 
    { 
     trackerObj.showMessages(); 
     if (trackerObj.focusOnFirstInvalid()) 
     return false; 
    }; 


} 
return logintestContentViewModel; 
+0

ce qui est la sortie de console.log (textStatus); ? –

+0

s'il vous plaît fournir le journal de la console des outils de développement –

+0

l'erreur dit Demande méthode 'GET' pas pris en charge, mais dans votre code votre code ajax est de type: "POST" –

Répondre

0

Dans l'exemple, vous avez POST comme valeur pour "type". Essayez de changer "type" en "méthode" et voyez si cela aide.

de l'API jQuery.ajax docs:

var menuId = $("ul.nav").first().attr("id"); 
var request = $.ajax({ 
    url: "script.php", 
    method: "POST", 
    data: { id : menuId }, 
    dataType: "html" 
}); 

request.done(function(msg) { 
    $("#log").html(msg); 
}); 

request.fail(function(jqXHR, textStatus) { 
    alert("Request failed: " + textStatus); 
}); 
0
if you wanna post and get a response use this 

var dataVal2 = {your data}; 
$.ajax({ 
type: "POST", 
url: "url", 
data: JSON.stringify(dataVal2), 
contentType: "application/json; charset=utf-8", 
dataType: "json", 
processData: true, 
success: function (data, status, jqXHR) { 
alert(data.result); 
var projectId = data.result; 
alert(projectId); 
    }, 
error: function (xhr) { 
alert(xhr.responseText); 
} 

if you want a response by using GET method use this 

var data = {your data}; 
        $.getJSON("url", data).then(function (resData) { 
        self.DataResponse(resData); 
        }); 
and your error function alike in post method