开发者

cUrl Converting into Javascript possible?

开发者 https://www.devze.com 2022-12-21 08:29 出处:网络
is there a way to convert this into javascript? <?php $url = \'http://www.yourdomain.com/\'; $ch = curl_init();

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;
    ?>开发者_运维问答


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号