1

Any one help me . I am using the following code for calling web service in jquery mobile. But I am getting the error " Undefined". Please point out me where I done the mistake. THanks in advance.

Coding :

$.ajax({
type: 'POST',
url: "http://jquery.sample.com/nodes.json",
data: ({search_keys :theName}),
dataType: 'json',
timeout: 5000,
success: function(msg) 
{
   console.log(msg);      //here, I can see the result in browser.  
   alert(msg.message);    //Undefined Error
},
error: function(xhr, status, errorThrown) 
{
alert(status + errorThrown);
}
});      

JSON Output
[ { "type":"Business Profiles", "title":"Lakeview Restaurant", "user":"canwest", "date":"1280144992", "node":{ "nid":"67916", "type":"business_profiles", "language":"", "uid":"1", "status":"1", "created":"1278994293" } } ]

1 Answer 1

2

You're getting an array back, not a base object - and even then there's no message property that I can see, so it should be:

alert(msg[0].title);

Or, loop through them all - for example:

$.each(msg, function(i, profile) {
  alert(profile.type);
  alert(profile.node.nid);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.