0

I want to get the data response from my login webservice. Here is my web service http://41.128.183.109:9090/api/Data/getloginer?medid=a&pass=a (for testing). Here is my code:

$("#login").click(function () {
    var url = "http://41.128.183.109:9090/api/Data/getloginer?medid=a&pass=a";
    $.ajax({
        url: url,
        type: 'Get',
        success: function (data) {
            alert(data.Medical_id);
        },
    });
});

The alert() shows me undefined. Please advise on what the problem could be.

prime
  • 331
  • 1
  • 6
  • 17
  • 2
    Check the console for errors. I would guess you're being stopped by the Same Origin Policy. Is the web service you're calling local to the website? If so, use a relative path. – Rory McCrossan Jan 18 '16 at 08:34

3 Answers3

0

The result is an array, so in order to get that field you have to iterate the result or get the first item:

for (var i in data) { 
   console.log(d[i].Medical_id);
}

Or you can simply get the first result:

$.ajax({
  url: 'http://41.128.183.109:9090/api/Data/getloginer?medid=a&pass=a',
  type: 'Get',
  success: function (data) {
        alert(data[0].Medical_id);
  }
});
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
0
The JSON  result you are getting is :

[{"$id":"1","id":8,"Medical_id":"a","Password":"a","Name":null,"Email":null,"gender":null,"Type":null}]

use for each to iterate through  the results  or 
instead of this  you  can check the result like this :    
var data = [{ "$id": "1", "id": 8, "Medical_id": "a", "Password": "a", "Name": null, "Email": null, "gender": null, "Type": null }] 
alert(data[0].Medical_id);
Rahul Sharma
  • 453
  • 3
  • 10
0

If you develop application in localhost then refer this questions also.
"No 'Access-Control-Allow-Origin' header is present on the requested resource"


If you are using chrome, then use this link to use CORS enable plugin.
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en-US
hope this will help

Community
  • 1
  • 1
dhanushka
  • 343
  • 3
  • 12