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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:45:59+00:00 2026-06-04T03:45:59+00:00

JavaScript $.ajax({ type : ‘POST’, url : ‘post.php’, data: dataString, success:function (data) { if

  • 0

JavaScript

$.ajax({
    type : 'POST',
    url : 'post.php',           
    data: dataString,
    success:function (data) {
        if (data==null) { alert("darnit!!!!");}    
            //$("#response").append(data);
            alert(dataString);
        }          
    });     
});

in PHP file just a simple

print_r($_REQUEST);

Also tried

echo "got iT!";

But nothing, been looking of over tried differant things but no luck
first //alert (dataString); works
but after the success:function (data) I don’t get any alerts – no response within the page!

What am I doing wrong?

  • 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-04T03:46:00+00:00Added an answer on June 4, 2026 at 3:46 am

    There’s a SyntaxError in your snippet. I’m not sure if that’s also in your real code.

    Be sure to use json_encode in your PHP file and dataType: 'json' in jQuery.ajax. And always use an error callback as well. You don’t want your application to become indefinitely frozen if something fails.

    Something like this:

    $.ajax({
        url: 'api.php',        
        data: {
            action: 'greet',
            foo: 'bar',
            baz: 'quux'
        }, 
        type: 'POST',  
        dataType: 'json',
    }).then(function (response) {
        console.log(response); // DEBUG
        if (response.error) {
            alert('Greet Error: ' + response.error);
        } else {
            alert(response.greet);
        }
    }).catch(function (jqXHR) {
        console.log('AJAX Error', jqXHR); // DEBUG
        alert('AJAX Error: Request failed');
    });
    

    PHP:

    <?php
    $input = $_POST;
    $response = array();
    
    if (!isset($input['action'])) {
        $response['error'] = 'Action parameter required';
    } else {
        if ($input['action'] === 'greet') {
            if (!isset($input['foo']) || !isset($input['bar'])) {
                $response['error'] = 'Invalid greet request';
            } else {
                $response['greet'] = 'Welcome home, David!';
            }
        } else {
            $response['error'] = 'Unknown action';
        }
    }
    
    header('Content-Type: application/json; charset=utf8');
    echo json_encode($response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<script type=text/javascript> function testing() { $.ajax({ type: POST, url: testing.php, data: call=+$(#abc).val(), success: function(msg){
In my document I have this script: $.ajax({ type:POST,url:ajax.php,data:data, success: function() { //onsuccess },
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
Here's some javascript: $.ajax({ type: POST, url: default.aspx/GetDate, contentType: application/json; charset=utf-8, data: {}, dataType:
I'm missing something here. I've got this jQuery JavaScript: $.ajax({ type: POST, url: /update-note-order,
JavaScript code I'm starting with: function doSomething(url) { $.ajax({ type: GET, url: url, dataType:
How do I send AJAX data through $.ajax() in JavaScript via type: POST using
I am making a jQuery ajax post in a javascript function used by a
Why in this scenario is id null when it reaches the Action? Javascript $(#ajax-submit).click(function
Here is my jQuery code: <script type=text/javascript> //<!-- $(document).ready(function() { $('input[type=submit]').click(function() { $.ajax({ type:

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.