Deepika
Deepika

Reputation: 826

Not getting Jquery response

I have return small function. I can see the response in console but i am not getting response when i do alert(response).

$.ajax({
    url: "/students/results?start="+start+"&end="+end_date+"&id=<%= params[:id] %>",
       success: function (response) {
         alert(response);
       }
});

Please help.

Upvotes: 0

Views: 93

Answers (1)

Salil
Salil

Reputation: 47482

Best way to check json is open your chrome console copy paste below code and then enter

var myJSONObject = {"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
};

This will return undefined, Now paste below code and then enter

myJSONObject.bindings

This will return [Object, Object, Object]

Similarly for myJSONObject.bindings[0].ircEvent it will return PRIVMSG.

So check your response and you can write something like following

$.ajax({
    url: "/students/results?start="+start+"&end="+end_date+"&id=<%= params[:id] %>",
       success: function (response) {
         jQuery('#some_text_field_id').val(response.bindings[0].ircEvent)
       }
});

I hope this will help.

Upvotes: 1

Related Questions