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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:42:39+00:00 2026-06-05T07:42:39+00:00

This is my first attempt at AJAX and am unable to retrieve the output

  • 0

This is my first attempt at AJAX and am unable to retrieve the output from the data.php file.

Here is the code so far, not all code is included, just what is applicable:

index.php

<article class="post">
    <form name="form"><input type="hidden" name="postid" value="<?php echo $value['post_id'];?>" />
   </article>

<div id="main-post">
<div id="gotpostid">some text</div>
</div>

.js file

$(".cover-img").click(function(){
    $("#main-post").fadeIn(1000);
    $.post("data.php", {postid: form.postid.value},
        function(output){
              $("#gotpostid").html(output).show();
    });   
 });

data.php

<?php

    echo 'got this from data.php';
?>

the data.php file is in the same directory as the .js.

Currently when I click on the image it shows the “main-post” div but the “gotpostid” within it still only displays the “some text” and doesn’t replace it with the output text from the php file.

This is the result of adding the following code:

.fail(function(x,y,z){ $("#gotpostid").html(x + "<br />" + y + "<br />" + z)})

[object Object] error Not Found

I found the error mostly thanks to Kevin B’s suggestion for adding the .fail().

The url wasn’t correct for the .php file, it should have been js/data.php.

  • 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-05T07:42:41+00:00Added an answer on June 5, 2026 at 7:42 am

    Add a error method to your ajax handler to know if something unexpected is happening

    $(".cover-img").click(function(){
        $("#main-post").fadeIn(1000);
        var jqxhr = $.post("/echo/html/", {postid: form.postid.value},
            function(output){
                  $("#gotpostid").html(output).show();
        })
        .error( function()
        {
            console.log( "error" );      
        })
    
        return false;
     });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first attempt at AJAX, and so I'm keeping it simple. I've
This is my first attempt at adding ajax to a WordPress plugin. I have
This is my first attempt at AJAX, and I'm running into three specific problems.
This is my first attempt to prototype. I want to initiate an AJAX request
I'm not able to get this to work - this is my first attempt
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
this if my first attempt at using streaming for WCF, and I am struggling
This is my first attempt to create a GUI in MATLAB. I haven't been
this is my first attempt at a responsive design so excuse me if this

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.