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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:51:43+00:00 2026-05-25T23:51:43+00:00

This is my first attempt to prototype. I want to initiate an AJAX request

  • 0

This is my first attempt to prototype. I want to initiate an AJAX request that should get a JSON response and alert that. I have done following so far.

JS:

<script type="text/javascript">

function ajaxRequest() {

    var url = '/ajaxresponse';

    new Ajax.Request( url, {

         method: 'get',
         onSuccess: function(transport,json) {
            alert(json ? Object.inspect(json) : "no JSON object");  
         },     
         onFailure: function(){ 
            alert('Something went wrong...') 
         }  
    });
}

</script>

HTML:

<a href='javascript:ajaxRequest();'>Testing AJAX</a>

JSON source:

function ajaxresponse() {

    // Data
    $data = array("New York", "New Yorkshire", "New Jersey");
    // encode and return json data
    echo json_encode( $data );
}

On clicking “Testing AJAX” link I am getting following result in alert box:

no JSON object

Any idea ?

Thanks

  • 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-25T23:51:44+00:00Added an answer on May 25, 2026 at 11:51 pm

    I dont see any second variable passed to onSuccess handler in prototype. Look here. There is only transport object. So this should help:

    ...
    onSuccess: function(transport) {
          var json = transport.responseText;
          alert(json ? Object.inspect(json) : "no JSON object");  
     }, 
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Because this is my first attempt at an extension method that seems quite useful
Up front: This is my first attempt at an Android app. I'm in that
This is my first attempt at AJAX, and so I'm keeping it simple. I've
This is my first attempt at a JOIN MySQL statement... I have 2 tables..
This is my first attempt at creating a Windows service that calls multiple threads.
First, let me just mention that this is my first attempt at a from-the-ground-up
This is my first attempt at java problem I have been given as part
this is my first attempt at dynamic pivoting in SQL and I have become
This is my first attempt at responsive design, so I'm keeping it simple. I
This is my first attempt to write shorthand if statements however am befuddled by

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.