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 8600329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:35:33+00:00 2026-06-12T01:35:33+00:00

I am using JSON data from an AJAX call to build a url and

  • 0

I am using JSON data from an AJAX call to build a url and display the Google Map API image on a modal. This means that I am editing the innerHTML using jQuery. To do this,

To show the image, I have to use javascript to reference the longitude and latitude values and build the link.

var google_map_url = 'http://maps.googleapis.com/maps/api/staticmap?center=' + data.location.latitude + ',' + data.location.longitude + '&zoom=14&size=400x300&sensor=false';

"<%= escape_javascript(image_tag " +google_map_url+ ")%>"

The problem is that I am also using escape_javascript with my image_tag (shown above) and this does not generate a picture. My view simply displays +google_map_url+.

The other escape_javascript image_tag works because I don’t have to break up the string into components: "<%= escape_javascript(image_tag photo[:url]) %>"

How can I work around this so that I can still generate my image while using javascript variables?

index.html.erb

<div class="body_container">

    <div id="photos_container">
    <% @photos_array.each do |photo| %>

      <%= link_to '#' do %>
        <div class='each_photo_container', id='<%="#{photo[:id]}"%>' >
          <%= image_tag photo[:s_url] %>
        </div>
      <% end %>


    <!-- Load Modal onClick -->
    <script type="text/javascript">
    jQuery(function() {
      $('#<%=photo[:id]%>').click(function (e) {

        //ajax call to fetch photo info

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

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

               var google_map_url = 'http://maps.googleapis.com/maps/api/staticmap?center=' + data.location.latitude + ',' + data.location.longitude + '&zoom=14&size=400x300&sensor=false';          

            //edit innerHTML of basic_modal
            $('.basic_modal').html(

              "<div id='googlemap_image'>"+
                "<%= escape_javascript(image_tag " +google_map_url+ ")%>"+
              "</div>" +

              "<div id='modal_image'>"+
                "<%= escape_javascript(image_tag photo[:url]) %>"+
              "</div>"+

              "<div id='modal_photo_info_container'>"+
                 "<div class='modal_photo_attr'>"
                    +data.title+ 
                 "</div>"+ 
                 "<div class='modal_photo_attr'>"+
                    "By: " +data.owner.username+ 
                 "</div>"+ 
                 "<div class='modal_photo_attr'>"
                    +data.location.region._content+ ", " +data.location.country._content+ 
                 "</div>"+
              "</div>"


             );

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

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


        return false;
      });
    });

    </script>


    <% end %>

    <div class="basic_modal">
    </div>

  </div>
</div>

photos_controller.rb

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-12T01:35:35+00:00Added an answer on June 12, 2026 at 1:35 am
    "<%= escape_javascript(image_tag " +google_map_url+ ")%>"
    

    If you write like above one, it will be treated as following

    1. "<%= escape_javascript(image_tag "
    

    2.+google_map_url+

     3.  ")%>"
    

    To get desired value, replace inside [ ” ] with [ ‘ ], corrected syntax should be look like

    "<%= escape_javascript(image_tag ' +google_map_url+ ')%>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display JSON data that I retrieve from an ajax call
I'm using CoffeeScript and jQuery, trying to get the data from an ajax call
I was trying to get data back from an ajax call, and was using
First, I'm using an NSURLConnection to download JSON data from twitter. Then, I'm using
I am using Node.js (with Express.js) to pass a JSON data object from the
Is it possible to output specific JSON data (exported from Firefox bookmarks) using PHP.
I am using mongoose/nodejs to get data as json from mongodb. For using mongoose
I am calling an API that returns JSON data. I am using json.loads to
I parse data using JSON in javascript, I find this is very convenient. But
i Want to fetch this data using json decode. Please Help.. So far i

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.