how i define my controller :
def show
@user=User.find(params[:id])
respond_to do |format|
format.json { render json: @user.to_json, :only => [:name, :email]}
end
end
how i define my ajax function:
function FunAjax()
{
$.ajax({
type: "POST",
url: "
http://ip:3000/users/1.json",
data: "begin=1&end=9",
dataType: "json",
timeout : '50000',
error : function(){
alert ('server error');
},
beforeSend: function(){
$("#span_content").text("processing...");
},
success:function(data){
if(data === null){
alert('no data');
}else{
var div_cont ="";
$.each(data,function(idx,arr_item){
div_cont = div_cont +"<br/>key:"+idx+"value:"+ arr_item;
}),
$("#span_content").html(div_cont);
}
}
});
};
$(document).ready(function () {
alert('start');
});
then i browse the url:
http://ip:3000/users/1.jsonit will return a string like this:
{"name":"fang","email":"
fa...@fang.com"}
but the ajax function won`t work.
please tell me how can i exchange data between the server and the browser?