0

I make jQuery Ajax request which return output in XML format. i want to access this XML in PHP to Process on data. Below is sample of my code...

getTime.php File

<?php
    header("Content-type: text/xml");

    echo '<Dates>';

    echo '<Now ';
    echo 'val="' . date("h:m:s") . '" ';
    echo '/>';

    echo '</Dates>';
    //echo date("h:m:s");
?>

index.php File

jQuery(document).ready(function(e) {
    $('#btnTime').click(function(){
        getData("GetTime.php");
    });
});
function getData(strUrl)
{
    $.ajax({
        type: "POST",
        url: strUrl,
        dataType: "xml",
        success: function(output){
                    // I want to Retrieve this XML Object (output) to PHP
        }
    });
}

How can I access XML outputed by jQuery in PHP? Please help me..

7
  • the output refers to the data returned by the ajax request... did you try it Commented Sep 7, 2013 at 11:16
  • You want to send your XML back to PHP? Commented Sep 7, 2013 at 11:18
  • post it to another php file. Commented Sep 7, 2013 at 11:19
  • yaa.. output itself a XMLDocument object. Commented Sep 7, 2013 at 11:19
  • Why are you getting it with jQuery if you want to send it back to a PHP file? Commented Sep 7, 2013 at 11:21

1 Answer 1

1

You need to make another call to your webserver in the success callback.


function getData(strUrl)
{
    $.ajax({
        type: "POST",
        url: strUrl,
        dataType: "xml",
        success: function(output){
            $.ajax({
                type: "POST",
                url: strUrlToPostXml,
                dataType: "xml",
                success: function(output){
                    // Whatever you want, the Xml has been successfully posted back to Php
                }
            });
        }
    });
}

But it's quite weird to do that though: it would be much better to have everything done on the server side using the initial call.

Sign up to request clarification or add additional context in comments.

2 Comments

yaaa.. this is looking weird. I think i have to handle data in jQuery itself.
but, can i handle those data in jQuery in such a way that i can do server side events on those data? for e.g. I want to display data in tabular form returned from database by jQuery Ajax request and then updation on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.