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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:42:12+00:00 2026-06-09T08:42:12+00:00

How do I display ajax response on particular div? This statement worked alert(data[i][‘title’]); but

  • 0

How do I display ajax response on particular div? This statement worked alert(data[i]['title']); but I want to display on div. thanks

<td><a onclick="ajax_request('{% url recommendation id=track.id %}');" href="#"> Click Here</a></td> 

Ajax Function

function ajax_request(url) {
    $.ajax({
        url: url,
        type: 'POST',
        data: {csrfmiddlewaretoken: '{{ csrf_token }}'},
        success: function(data) {
                for(i=0;i<=data.length;i++){
                    alert(data[i]['title']); 
               }
            }
    })
}

View

@login_required
def recommendation(request, id):
    if request.is_ajax() and request.method == 'POST':
        track = Track.objects.get(pk=id)
        recommend = Song.objects.filter(title__icontains=track.title)[:5]
        results = []
        for data in recommend:
            results.append({'title': data.title})
        json = simplejson.dumps(results)
        return HttpResponse(json, mimetype="application/json")
  • 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-09T08:42:14+00:00Added an answer on June 9, 2026 at 8:42 am

    Hm, depending if you already have a div you want to display the content in or you create a new one with jQuery:

    Existing one with id myDiv:

    $('#myDiv').html(data[i]['title']);  //also $('#myDiv').text(data[i]['title']) possible
    

    Create new div:

    $('<div/>').html((data[i]['title']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing an ajax post in my code like this, $.post(myAction,$(#myForm).serialize(), function(response) {alert(response);});
I am using this gem to search for youtube videos and display with ajax
I have created ajax code for my city tabs to display respective city data
I want to display different types of objects in the same ajax called controller
I want to display a success msg after finishing an Ajax call. I tried
EDITED I'm trying to use jquery/ajax to display data returned from a django method.
I want to display some Amazon products, loaded via Ajax. I call the method
This function is my ASP.NET MVC Ajax error handler. I want to get the
I am trying to display JSON data that I retrieve from an ajax call
By using Alert on the response paramater after a jquery success will display the

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.