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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:23:03+00:00 2026-06-10T08:23:03+00:00

I am working on a project where I will read data from google maps

  • 0

I am working on a project where I will read data from google maps API and convert it to XML for each object and then store that XML in an array slot (This will happen multiple times until all of the data is read) I will then make an Ajax POST request to a PHP file sending the array full of XML and a boolean (to let the server know which request it is). The PHP will then use SimpleXML to load, edit the XML with the data received, and then save it.

My problem is when I make the ajax request Firebug will recognize a POST request and it is sending all of the correct data. It throws a 302 (error?) saying Moved Temporarily Then a GET request happens (which I think is initated by the server) which outputs an error saying Undefined inded: ajax on the line where I ask if the boolean (which is called ajax) is true. And then when I check my XML file all data is deleted (the file still exists but there is no longer any XML in it) I am very confused as to how to troubleshoot this problem and I’m not really sure what to do. Here is some of my relevant code.

Thank you in advanced for any help that you can provide. Any assistance would be extremely helpful!

Also, please feel free to comment if you need me to clarify on anything.

javascript

function sendData(result)
{
    $.ajax(
    {
        type:'POST',
        url:'getXML.php',
        traditional: false,
        data:
        {
            //Result is an array full of XML
            'myXML': result,
            //The ajax boolean is for letting the PHP know that it is this request
            'ajax' : true
        },
        success: function(data)
        {
            $('#output').text(data);
        }
    })
}

PHP

<?php
    //Set error reporting
    ini_set('display_errors', 1);
    ini_set('log_errors', 1);
    ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
    error_reporting(E_ALL);

    //Checks if the get request is from the AJAX call
    if($_POST['ajax'])
    {
        //////////////////////////////Code for editing XML/////////////////////////////////////////
        //Checks to see if the xml file exists.
        if (file_exists('business.xml')) 
        {
            //Loads the XML file
            $xml = simplexml_load_file('business.xml');
            $result = $_POST['myXML'];
            //Append XML to existing file using data loaded in from AJAX request
            appendXML($xml, $result);   
        } 
        else 
        {
            //Loading XML has failed
            exit('Failed to open business.xml.');
        }
    }

    function appendXML($xml, $xmlResult)
    {
        foreach($xmlResult as $result)
        {
            //Creates new business node
            $business = $xml ->addChild('business');

            //Adds XML to business node (Please oh dear god let this work)
            $business ->addChild($result);

            file_put_contents("business.xml", $xml);
            header('Location: getXML.php');

        }
    }
?>
  • 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-10T08:23:05+00:00Added an answer on June 10, 2026 at 8:23 am

    The issue you’re having is with this line:

    header('Location: getXML.php');
    

    On the first run through of the page, things are working fine, and the appendXML codeblock is being called. When that happens though, you’re doing a header redirect to the same page (I’m not sure why). When THIS happens, the page reloads, but in the new page non of the post data that you had set before is set. As a result $_POST is empty and your if statement fails, further $_POST[‘myXML’] is also empty, which would blank out your XML.

    If you need to do this reload of the page for some reason, consider creating a session and storing your values in a session variable. You should also look at sanitizing the data you’re passing in, as your current code has a vulnerability where someone can inject whatever information passed in from the browser into an XML file on your server. This might not be a big deal but I’m always worried about letting someone write anything unescaped into a file on my system directly. If nothing else someone could maliciously max out the space on your drive with this.

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

Sidebar

Related Questions

In a project I'm working on, I need to read from a CSV file,
I am working on a project that will require internationalisation support down the track.
I'm working on a project which will deliver small pieces of text to a
I'm working on a project that will require me to implement a calendar. I'm
I'm working on a project that will require me to take various .vbproj and
I'm working on a project which will end up have a lot of application
I'm working on a project that will have a single table holding lots and
I'm working on a project which will involve running algorithms on large graphs. The
I am going to be working on a project that will heavily involve indexing
I am working on a project where I will let users submit small 'scripts'

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.