1

is there a way to convert this into javascript?

  <?php
      $url = 'http://www.yourdomain.com/';
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      $output = curl_exec($ch); 
      curl_close($ch);

      echo $output;
    ?>
1
  • Why do you need to move it to js? What platform is this on? Commented Mar 1, 2010 at 11:04

3 Answers 3

1

Pure JavaScript? No.

JavaScript with a standard browser environment? Maybe. There is the XHR object (which includes the status property, which will tell you if it was successful or not), but there is also the same origin policy.

Sign up to request clarification or add additional context in comments.

Comments

0

Not directly. You can use XMLHttpRequest to download webpages, but there are cross-domain issues to be aware of.

Comments

0

You can't but you can:

Actually you can save the php code to, let's say, mycurl.php, in your server, then use AJAX (XMLHttpRequest) to pass the url to mycurl.php and get back the response to your javascript function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.