views:

69

answers:

2

I have a client side code in jquery and from client side code I need to store some data on server side in form of XML files that are written using PHP. I'm done with the code for writing PHP files. However, I'm not able to pass client side code to PHP file. jQuery post is also not working. I tried query strings but as I said data is too large thus it doesn't work.

Any suggestions?

Thank you for your time and consideration.:)

Some Test Code:

jQuery POST

$.post("test2.php", { userdata: "test"} );

Ajax POST

$(document).ready(function() 
{
    $(document).ready(function() 
    {
        $.ajax({
            type: "POST",
            url: "test2.php",
            data:   "userdata=" + "test" 
        });     
    });

});

PHP Code

$test = $_POST['userdata']; $document = new DOMDocument(); 
$document->load("collection.xml");
//Write XML file generation code
A: 

pass serializeArray() in case of form data. or create an array from the contents you want to send. for example

var sendingData = [];
sendingData = fillinData();
   OR
sendingData = $("form").serializeArray();
$.post("url.php", { xmlData: sendingData }, function(data){   });

loop through that data on server side for creating xml. You should use array so that no matter what is the size of contents it got wrapped up in a variable which can be fetched on server side.

http://stackoverflow.com/questions/713884/convert-js-array-to-json-object-for-use-with-jquery-ajax

Ayaz Alavi
A: 

As I understand it your problem is not receiving and writing out the data, but writing that data into a file stored on the server. For this you need to use something like the php function fopen:

$handle = fopen("filename.xml", 'w');
fwrite($handle,$datafromclient);
fclose($handle);

I'm not sure why you want to write the data to files on the web server rather than store the information in a database but I'm sure you have your reasons. Just be sure to consider the security implications and make sure people can't, for example, upload executable code and that permissions are set properly (and data is sanitised properly).

Good luck :)

sillyMunky