0

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

  • More code or a better explanation is needed... – logic-unit Apr 11 '14 at 14:12
  • where is the ajax call? – Subir Kumar Sao Apr 11 '14 at 14:15
  • 1
    not working **HOW**? you're not capturing the return value of `curl_exec()`, so if you're trying to fetch anything from that url, it's just being thrown away. Plus, if the exec fails, the return value would be a boolean FALSE, which you're also not checking for. As for ajax, that's not ajax. That's just PHP doing an HTTP request via HTTP. An AJAX call is done from a client browser back to a server. – Marc B Apr 11 '14 at 14:15
  • Is there any error in Ajax call? `curlSession` without `$` seems to me error. – dikesh Apr 11 '14 at 14:21

1 Answers1

0

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.

Community
  • 1
  • 1
Guns
  • 2,678
  • 2
  • 23
  • 51