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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:56:44+00:00 2026-05-27T02:56:44+00:00

I have a form, in which I need to send data selected via AJAX

  • 0

I have a form, in which I need to send data selected via AJAX to. The whole idea is once the form data has been selected, an ajax call sent via jQuery.get() calls another function which receives and decodes the data in PHP and uses that data as an id to get more data from a database. The data from the database is then re-encoded and sent to a javascript function which prints more data, based on what was passed.

My problem is that, anytime I reference either $_GET or $_POST using <?php ?> tags in a javascript function, I get an error telling me that my javascript functions are undefined. I know that this is working partially, at least, because the AJAX call does get sent when I remove the $_GET/$_POST superglobal.

Any help with this would be greatly appreciated.

Here’s my code:

jQuery.noConflict();        

function printSubCategories(categories) {

    for (var i = 0; i < categories.length; i++) {

        var opt = document.createElement('option');

        opt.text = categories[i]['name'];
        opt.value = categories[i]['id'];

        jQuery('#subcategories').append(opt);
    }    
}

function recieveAndPrint() {
<?php
    $categories = getCategories(json_decode($_GET['parent']));
?>
    printSubCategories(<?=json_encode($categories)?>);
}

function ajaxCategories(pathToFile, ajaxData) {  
    jQuery.get(pathToFile, {'parent' : ajaxData}, function(ajaxData) {
        //alert('Data loaded: ' + ajaxData + <?=json_encode($_POST)?>);
    });

    recieveAndPrint();

}
  • 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-27T02:56:45+00:00Added an answer on May 27, 2026 at 2:56 am

    I suspect you’re confused about how the AJAX is working. It looks like you expect that the AJAX call can work with PHP located on the same page in a way that the page is loaded only once. That’s not accurate; what you need is another php page that is called on the server that returns the data as JSON to the original page. You’ve also got an issue with your callback, as the data will not be ready before receiveAndPrint() is called; it needs to be called in the callback (but it will only be print at that point, since the receive part will already be done).

    Let’s say you have two PHP files, a.php and b.php. The first will be used to display the initial page and will call the second to retrieve the new data for a particular instance of parent.

    a.php

    jQuery.noConflict();        
    
    function printSubCategories(categories) {
    
        for (var i = 0; i < categories.length; i++) {
    
            var opt = document.createElement('option');
    
            opt.text = categories[i]['name'];
            opt.value = categories[i]['id'];
    
            jQuery('#subcategories').append(opt);
        }    
    }
    
    
    function ajaxCategories(pathToFile, ajaxData) {  
        jQuery.get(pathToFile, {'parent' : ajaxData}, function(data) {
            printSubCategories(data);
        });
    }
    

    called as

    ajaxCategories('/b.php','value_of_parent');
    

    b.php

    <?php
        $categories = getCategories(json_decode($_GET['parent']));
        header('Content-type: application/json');
    ?>
    <?=json_encode($categories)?>
    

    You might also want to make sure the response isn’t cached.

    header('Cache-Control: no-store');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Ajax call which send form data to a page and
I need to have a checkbox which ajax-submits a form. The following code throws
i have a form button in the form,which i need to perform basic action
I have a form which has a lot of SELECTs. For various reasons, I'd
I have a form which has only tab control in it. I want to
I have a form which is a mdicontainer and has a menu strip at
I have a form on my site which sends data to some remote site
I have a problem while I need to send data using uploadify script. For
I have a form in HTML which when submitted makes a call to the
I have a form which is used to insert/display and update . In the

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.