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

  • Home
  • SEARCH
  • 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 6036635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:57:13+00:00 2026-05-23T05:57:13+00:00

I have a jQuery ajax call that looks like this: $.ajax({ type : ‘GET’,

  • 0

I have a jQuery ajax call that looks like this:

    $.ajax({
       type     : 'GET',
       dataType : 'json',
       url      : '/Zoo/animals',
       success  : function(data){
           var count = data.length;               
           for(var i = 0; i < count; i++) {
               ${'#tableBody').append('<tr><td>');
               ${'#tableBody').append('<a href="@{Animal.index(data[i].name)}">' + data[i].name + '</a>');
               ${'#tableBody').append('</td></tr>');
           }
       }
    })

Now all of this works fine except for the href attribute. Play! gives me the following error:

Exception raised was NullPointerException : Cannot get property 'name' on null object.

The json string that gets returned from the ajax call is fine as the text of the link shows up as the name of the animal as expected. I would like to pass the name of the animal to the Animal.index action however have been unable to do so.

Update:

As others have mentioned, I have also tried this:

${'#tableBody').append('<a href="@{Animal.index(' + data[i].name + ')}">' + data[i].name + '</a>');

which just results in the link of:

localhost:9000/animal/index?name=+%2B+data[i].name+%2B+
  • 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-05-23T05:57:14+00:00Added an answer on May 23, 2026 at 5:57 am

    The problem is that Play! generates the url when the file is served, well before any javascript is executed. No change to the string or quotes here or there is going to help you.

    A workaround:

    var url = "@{Animal.index(XXX)}".replace('XXX', data[i].name);
    ${'#tableBody').append('<a href="'+url+'">' + data[i].name + '</a>');
    

    This allows Play! to generate its url at “compile” time, and then javascript simply executes a replace at “run” time. Not sure if Play! will look for a variable named XXX, if so, add a dumby variable named XXX with value “XXX” on the server side.

    UPDATE

    I don’t have a Play! instance in front of me to fiddle with, but instead of a variable, you could probably also insert the string directly as a value by quoting the XXX:

    var url = '@{Animal.index("XXX")}'.replace('XXX', data[i].name);
    

    And then you wouldn’t need a variable named XXX. The details require a bit of playing around, although the idea is the same.

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

Sidebar

Related Questions

I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
I have some jQuery with an Ajax call that looks like this: $.ajax({ type:
I have a simple ajax call like this: $.ajax({ url: u, type: POST, dataType:
A situation I ran across this week: we have a jQuery Ajax call that
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
I make an AJAX request like so using JQuery: $.ajax({ type: GET, url: getvideo.php,
Hei guys i have this JQuery Ajax call from my view and it looks
On my main page I have this jquery code which does an ajax call
I have a method in codeigniter that looks like this, public function category() {

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.