Amanada Smith
Amanada Smith

Reputation: 1981

Using jquery to pull from ajax response

http://localhost:2000/WebService/Handler.ashx?d=ck

Response when viewing URL:

{"Status":"OK","Message":"0","Info":"(none)"}

Using JQuery how do I pull from that? I get how you do POST and sending but little lost has to how to pull from that. Do I use GET?

Am I doing something like $.get("URL HERE"...?

Upvotes: 0

Views: 265

Answers (3)

Nishu Tayal
Nishu Tayal

Reputation: 20860

Use jQuery.ajax or jQuery.getJSON function of jquery.

 $.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback
});

Or this way...

 $.getJSON('ajax/test.json', {data: data },function(data) {
      // do as needed
 });

Upvotes: 0

Zbigniew
Zbigniew

Reputation: 27614

You can use ajax function to retreive your JSON response:

$.ajax({
  url: 'http://localhost:2000/WebService/Handler.ashx?d=ck',
  dataType: 'json',
  success: function(data) { 
      console.log(data); 
      console.log('Status: ' + data.Status); 
  }
});

Upvotes: 1

gdoron
gdoron

Reputation: 150303

$.ajax({
    url:"...",
    dateType: "json", // <=== you expect "JSON" string
    success: function(data){ 
        alert(data.Status); // Extract the data from the response.
        alert(data.Message);
        alert(data.Info);            
    }        
});

Or the shorthand getJSON function:

$.getJSON(url,function(data){
    data.Status;
    ...
});

Upvotes: 2

Related Questions