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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:24:16+00:00 2026-05-31T03:24:16+00:00

When I make the POST to a PHP page, the echo’ed data still comes

  • 0

When I make the POST to a PHP page, the echo’ed data still comes back to me but the jQuery AJAX says it’s not a success. Why would this be? And further, how can I actually “print” out the data once I get it back?

My PHP is below:

<?php 
$userEmail = $_POST['username'];
$userPassword = $_POST['password'];
//Login Function
$data = array("username" => $userEmail, $userPassword => "password");                                                                    
$data_string = json_encode($data);                                                
$ch = curl_init('http://*****/****/**/Login');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                 
curl_setopt($ch, CURLOPT_VERBOSE, 1 );                                                                  
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json')                                                                       
);                                                                                                                   
$result = curl_exec($ch);
$obj = json_decode($result);
echo $obj;
echo '<br /><br />';
echo '<b>Each array and objects in table:</b> <br />';
echo '<hr>';
echo '<br />';
echo '<table border="1">';
echo '<tr><td>Medical Entity:</td><td>Date:</td><td>Type:</td><td>ID:</td></tr>';
foreach ($obj as $key => $value) {
    echo '<tr>';
        echo '<td>' . $value->date . '</td>';
        echo '<td>' . $value->Name . '</td>';
        echo '<td>' . $value->dealType . '</td>';
        echo '<td>' . $value->id . '</td>';
    echo '</tr>';
}
echo '</table>';
?>

The jQuery AJAX is below:

<div id="test">
Testing Stuff!
</div>

<script>
$(document).ready(function() {
$('#submit').click(function () {
var username = '***@****.com';
var password = 'password';
var data = '&username=' +  username + '&password=' + password;

        $.ajax({  
            type: "POST",  
            url: "/****/data.php",  
            data: data,  
            dataType: "json",  
            success: function(e){   
                for(var i=0;i<e.length;i++){
                    document.write(e[i]);
                }
            },  
            error: function(e){   
                for(var i=0;i<e.length;i++){
                    $('#test').html(e[i]);
                } 
        });  

  //cancel the submit button default behaviours
        return false;
    }); 

});
</script>

My ultimate goal is to write out the data I get from the PHP page to a DIV on my HTML page via AJAX.

  • 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-31T03:24:18+00:00Added an answer on May 31, 2026 at 3:24 am

    You are calling your php function using dataType: json, meaning jQuery is expecting a JSON result to be returned. Your php file is returning HTML. Remove the dataType: JSON setting.

    The variable that gets passed to the success function is not an array. You just need to do something like $('#test').html(e);

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

Sidebar

Related Questions

I make a post request to the the page getremote.php with post data but
I want to make a php ajax post.(post value without refresh the page) here
I want to make a php ajax post.(post value without refresh the page) here
I am using jQuery to make a POST to a PHP file with the
I'm using jQuery to make an Ajax call using an Http Post in ASP.NET
Simply this the code for PHP page the uses AJAX to upload file, but
I am using ajax with jQuery to make a request from a page on
I'm working at an app which would make a POST ajax request to a
I'm using jQuery. This is my second post to make my old question more
I'm currently trying to make a page via php which allows the user to

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.