Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:20:18+00:00 2026-06-11T21:20:18+00:00

I have an ajax call to fetch information from Flickr API which returns JSON

  • 0

I have an ajax call to fetch information from Flickr API which returns JSON data. I want to display values from JSON data in my view. I do this by editing some innerHTML with jQuery. The problem I am having is that the data is undefined, so it looks like a scoping problem.

photo.js

jQuery(function() {
  $('#<%=p[:id]%>').click(function (e) {

    //ajax call to fetch photo info

    var fetch_id = '<%=p[:id]%>';
    var fetch_secret = '<%=p[:secret]%>';  

    $.ajax({
      type: 'GET',
      url: '/photos/fetch_info',
      dataType: 'json',
      data: { 'id' : fetch_id, 'secret' : fetch_secret },
      success: function(data){

        console.log(data)  //returns Object
        console.log(data.title)  //returns appropriate title

        //edit innerHTML of basic_modal
        $('.basic_modal').html(
          "<div id='modal_image'><%= escape_javascript(image_tag p[:url]) %></div><div id='photo_title'><%=data.title %></div>"
         );

        //load modal
          $('.basic_modal').modal({
          overlayClose:true
        });

      } //end success: function(result)
    });

When I print data.title to console, I get the appropriate title. However, when I try to edit HTML and render <%=data.title %>, I get an undefined variable/method error.

Any tip on how I can display the data in my modal in the view?

Here is my controller:

def fetch_info

  @info = flickr.photos.getInfo(:photo_id => params[:id], :secret=> params[:secret])

  respond_to do |format|
    format.json { render :json => @info }
  end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:20:19+00:00Added an answer on June 11, 2026 at 9:20 pm
     var result = jQuery.parseJSON(data);
    

    You donot need to do this, Because datatype:JSON already parse the data

    $('.basic_modal').html(
              "<div id='modal_image'><%= escape_javascript(image_tag p[:url]) %>
    </div><div id='photo_title'><%="+data.title+" %></div>"
             );
    

    this might help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an ajax call $.ajax({ url: '<%=Url.Action(SaveDetails,Survey) %>', dataType: 'JSON', cache: false, data:
I am using JSON data from an AJAX call to build a url and
I have a simple form which updates values in the db via ajax call
As you can see I am retrieving JSON data from my ajax call but
I'm making an ajax call to fetch json data. What I get is something
I have an ajax call in my code. What I want to achieve with
I have an AJAX call getting info out of the Github API. It is
I have an ajax call. I put the return value (data) in a variable
I have a jQuery ajax call that returns html of a table. Now I
I have a data fetching method that uses jQuery.ajax() to fetch xml files. /*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.