I'm looking for a method to execute a URL from an AJAX page.
The scenario is like im creating a bidding page with 3 products. Time limit is 5 second and after finishing 5 seconds, i wanted to insert the selected product details to database (this is why we need to execute a URL) and the loop should again start from 5 ..4..3..
The issue i'm facing right now is, i can not able to execute a url from this ajax call. I tried CURL; but this is not working.
$.ajax({
url: "test.php",
context: document.body
}).done(function() {
$( this ).addClass( "done" );
});
test.php
--------
curlSession = curl_init();
// HERE I NEED TO EXECUTE THE URL
curl_setopt($curlSession, CURLOPT_URL, 'http://192.168.1.132/oxid/index.php?fnc=tobasket&aid=378442f7aa427425c741607aa3440ee8&am=1');
curl_exec($curlSession);
curl_close($curlSession);
Regards, Tismon
You can try this and confirm if this solves your purpose:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'headers that you want to pass');
curl_setopt($ch, CURLOPT_URL, 'url/that/you/want/to/call');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
Posted thinking that you need help on basic curl
For using Ajax, you should look at this post.