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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:02:08+00:00 2026-05-25T10:02:08+00:00

How do I send AJAX data through $.ajax() in JavaScript via type: POST using

  • 0

How do I send AJAX data through $.ajax() in JavaScript via type: “POST” using JSON data formatting and how do I receive the data in a PHP script (through $_POST??) and put it into an array so I can use it? I’ve been kicking at this for hours and I have no idea what I’m doing wrong. If someone could post the JS and PHP code for sending and receiving JSON formatted data, I would be eternally grateful!!!!!

JS Code:

$.ajax({
                type: "POST",
                url: $(location).attr('protocol') + "//" + $(location).attr('hostname') + "/ajax/rate.php",
                data: {
                    "value1": 1,
                    "value2": 2,
                    "value3": 3,
                    "value4": 4,
                    "value5": 5
                },
                dataType: "json"
            });

PHP Code:

I was just using $_POST[“value1”], etc., to get that value. On that note, is there a way to make the ajax request GET instead AND open up a new window with that GET data on it so I can see what’s going on??

  • 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-25T10:02:08+00:00Added an answer on May 25, 2026 at 10:02 am

    The idea is to create a php page the outputs data in JSON form. This data is taken from an array and echoed using the json_encode function. Using the $.ajax() method from jQuery, you send a request to that page and manipulate the data in the success: function.

    Example.

    PHP – array.php

    $array = ("flag" => 1); 
    echo json_encode($array);
    

    JavaScript

    $.ajax({
      url : '/array.php', // page containing JSON data
      dataType : 'json', // must be specified for JSON manipulation in success
      success : function(data) { 
           // this function is called if the call to test.php is successful
           // access the data using object dot syntax
           alert(data.flag); // should display '1'
      }
    });
    

    // Send data to server this way
    PHP – test.php

    echo $_POST['data'];
    

    JavaScript

    $.ajax({
      url : '/test.php',
      dataType : 'text', 
      type : 'post',
      data : { data : 'Hello, World!'},
      success : function(data)          
           alert(data); // should display 'Hello, World'
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP to send a json string to jQuery ajax. I am
I have made an AJAX chat using Javascript, PHP, and MySQL. I send the
I have data that I want to send through an ajax GET request in
I am working on a comment script using ajax, json and jquery. I have
In a POST to an MVC controller, I'm using JQuery to send a JSON
When i am trying to send data through ajax, its not passing data $('#savenew').click(function
How do i use ajax to send POST requests to the server instead of
Hey guys, I have a program that uses ajax to send a post to
I send email through Outlook using VB.Net 2005; this is working fine. At the
I've written a CMS which uses the PHP function json_encode to send some data

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.