tags:

views:

41

answers:

2

Background: I am attempting to do a couple of unit tests on AJAX requests which would call PHP functions on the server-side. As this involves database manipulation, I have decided to check the return of the calls using unit tests in PHP.

Given the URL of an AJAX request, how do I call it and gets its response?

*Added question:*If the parameters include a form sent via POST, how shall I handle it?

+2  A: 

You could do this by making requests with CURL. You could even use phpUnit or some equivalent to track the progress.

<?php
$session = curl_init($request); 
curl_setopt($session, CURLOPT_HEADER, false); 
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session); 
curl_close($session); 
Garrett Bluma
A: 
$data = file_get_contents($url);
TML