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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:08:19+00:00 2026-06-09T19:08:19+00:00

I am just trying to do a simple $.post call. <body> <div id=main> <div

  • 0

I am just trying to do a simple $.post call.

<body>
<div id="main">
    <div id="diver">
    </div>
    <form id="entry_field_container" action="" method="post" accept-charset="utf-8">
        <input type="text" name="entry_field" value="" id="entry_field">

        <input id="send" type="submit" value="send">
    </form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        $('#send').click(function(e){
            e.preventDefault();
            var txt = $('#entry_field').val();
            $.post(
                'http://localhost/proc.php',
                {
                    name:'me',
                    text:txt
                },
                function(data){
                    console.log(data);
                    $('#diver').html(data)
                },
                'json'
            )

        })
    });
</script>

Inside proc.php:

<?php
    $name = $_POST['name'];
    $text = $_POST['text'];
    echo "{\"" . $name . "\", \"" . $text . "\"}";
?>

For some reason, the POST returns a 200, but the console never comes back with data, it’s just blank.

The hardest for me to understand is why this $.ajax function works every time. Is it not just a more verbose example of the same thing?

$.ajax({
    'type':    'POST',
    'url':     'http://localhost/proc.php',
    'async':   true,
    'cache':   false,
    'global':  false,
    'data':    {
       'name':'me',
        'text':txt
    },
    'error': function(xhr,status,err){
        alert("DEBUG: status"+status+" \nError:"+err);
    },  
    'success': function(data){
        console.log(data);
    }   
});
  • 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-09T19:08:21+00:00Added an answer on June 9, 2026 at 7:08 pm

    In your $.post you are telling jQuery that the returned text is JSON, but in your $.ajax you are not.

    The $.post fails because the text returned from PHP isn’t valid JSON.

    {"me", "test"}
    

    This isn’t valid JSON. {} is an object, so it needs keys:

    {"name": "me", "text": "test"}
    

    Or, maybe you want an array ([]):

    ["me", "test"]
    

    P.S. When creating JSON in PHP, it’s highly suggested you use json_encode instead of making the JSON yourself.

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

Sidebar

Related Questions

i am just trying to make a simple ajax call to shorten a url
i'm fairly new to django and just trying a couple simple experiments to get
Just trying to implement a simple audit logging solution with Grails 2.0.2 and it
I just started trying to build simple GUIs because I've always used command-line script
I'm just trying to get a simple example of accessing a custom java class
I am just trying to get my head around simple view switching for the
I'm just trying to do a simple text file read in java for my
I have a very simple workflow that is just trying to send an email
I'm trying to just draw a simple image from the drawable-mdpi folder in android
I am trying to do simple thing: I just need to set some cells

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.