1

When i click on login button. Below function will be called. Execution flow is going till $.ajax but its not going inside $.ajax. Can anyone please help me on this.

$('#login').click(function() {

    var contextroot = "/services/";

    var userName = $('#userName').val();
    var password = $('#password').val();
    alert("insid ::: ");    
    $.ajax({
        url: contextroot+"login",
        dataType: 'json',
        type: 'GET',
        contentType: 'application/json',
        data: {
            userName:userName,
            password:password
        },

        success: function(data){
            sessionStorage.setItem("userName", "sharana");
            window.location.href = '/admin/index.html';
            return false;
        }
    });



});
RSSM
  • 669
  • 7
  • 19
sharan
  • 21
  • 1
  • Do you get any errors in your console window? – ragerory Dec 07 '16 at 18:43
  • Have you tried [debugging](http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code)? Also, how are you determining that `$.ajax` is not being called? – Heretic Monkey Dec 07 '16 at 20:08
  • Note: [jQuery ajax, how to send JSON instead of QueryString](https://stackoverflow.com/questions/12693947/jquery-ajax-how-to-send-json-instead-of-querystring) – To send `data` to the server as `application/json`, you have to format it yourself. `jQuery.ajax()` only formats it for you as URL-Encoded query strings with `$.param()`. – Jonathan Lonowski Dec 08 '16 at 05:25

1 Answers1

0

Make available entire contextRoot in single variable as below

$('#login').click(function() {

  var contextroot = '/services/login';

  var userName = $('#userName').val();
  var password = $('#password').val();
  alert("insid ::: ");    
  $.ajax({
    url: contextroot,
    dataType: 'json',
  ....
  ...
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
  • Please add some explanation of why this code helps the OP. This will help provide an answer future viewers can learn from. See [answer] for more information. For this, I don't see why having `contextroot` concatenated with "login" would cause the error the OP is seeing. – Heretic Monkey Dec 07 '16 at 20:06
  • I am still facing same issue. I have uploaded the login.html and login.js code. Can you please check and suggest me on this. – sharan Dec 08 '16 at 15:02