I am making an ajax call to my controller. Controller is sending in the
response in an instance variable(as a json object). How can I access the
same in my ajax javascript?
def some_action
# after assigning a value to variable response
@response = Response.where(some condition)
respond_to do |format|
format.html #this will simply render the view
format.json { render :json => { :response => @response } }
end
end
I am getting an empty square bracket as my output. I am not able to find
out where I am wrong. Please guide me through.
I am making an ajax call to my controller. Controller is sending in the
response in an instance variable(as a json object). How can I access the
same in my ajax javascript?
After some operation in the controller, I am assigning a value to the
variable. When I print it in the controller using a "puts", I am getting
the right output. But when I render it to the view, I am NOT getting the
required json alert in the javascript. Where am I going wrong? Can you
please guide me?
Am I trying to send it wrong from the controller? I mean, is my syntax
wrong in sending the JSON from controller to the view? I have used such
a JSON in other methods in the controller. I have no issues there. But I
am not able to understand why I am not able to pass the same to the view
using respond_to in controller.
alert(object) calls object.toString() which returns [object Object] for any object. If you want to dump the contents of the object, loop through it and print each key-value pair.
My json data printed at the controller is correct. But my data.length at
the ajax javascript says "undefined". Even if i loop, it doesnt enter
the loop as data.length is undefined.
success(data){
var x = new Array();
alert("created new array");
for (var i=0;i<data.length;i++)
{
x[i] ,x[data[i].toString()]=function(){};
}
}