1

I need to save all the data received as answer from POST function.

jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )

If I understand it right, function calls url (something.php) and it respondes with data. Is there any way how can I store received data on my HDD ? Or maybe send received data elsewhere on my server where I can store them in DBS, or anyhow else.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Maroš Košina
  • 146
  • 2
  • 11

1 Answers1

0
jQuery.post('/someurl.php',
    {one:'value1',two:'value2'},
    function( response ) { alert(response); } );

On someurl.php, you would get these values with:

$oneValue = $_POST['one'];
$twoValue = $_POST['two'];

echo '{success:1}';

How you save them is then up to the PHP code.

EDIT JavaScript has specific restrictions from being able to access a local computer. Otherwise any hacker's script would be able to save files to your computer, which we wouldn't want.

You mentioned localhost in your comment above and that sounds like the best approach most likely. Post to the site, get the response, and then post the response to your localhost server where you do have access to the server side code to be able to save it to your computer. Something like:

jQuery.post('/someurl.php', {}, function( data ) { 
    jQuery.post('http://localhost/save.php', data, function() { alert('saved'); ]);
} );
Kevin Nelson
  • 7,613
  • 4
  • 31
  • 42
  • I dont have access to PHP code. It has to be done on client side, or send data on mine server where I can process them. – Maroš Košina Oct 23 '12 at 21:16
  • You can't do it via client-side code. You have to have server-side somewhere. It doesn't have to be PHP...just a page that can handle posted data. That was the point of the http://localhost/save example above...that you have to post your result to a server that you CAN control. – Kevin Nelson Oct 23 '12 at 21:25
  • Well problem is that javascript does not allow me to call "http://". It wants to stay on same server (just "/something"). – Maroš Košina Oct 23 '12 at 22:21
  • JavaScript wasn't intended for the purpose you're trying, so hitting a lot of roadblocks is expected. See if this helps with overcoming the cross-site scripting protections: http://stackoverflow.com/questions/1201429/jquery-ajax-fails-when-url-is-from-different-server – Kevin Nelson Oct 23 '12 at 22:25
  • It is not working for localhost. I am trying now to use greasemonkey to overrdide post function, or just grab the data it provides. No big success so far... Any ideas ? :) – Maroš Košina Oct 24 '12 at 16:26
  • Sorry, I wouldn't be able to help much more without actually trying to do it, since I've never tried to save data from a server I didn't have access to. – Kevin Nelson Oct 24 '12 at 17:12