How to call external url in jquery?

前端 未结 7 1634
再見小時候
再見小時候 2020-11-28 10:44

I am trying to put comments on Facebook wall using jquery.

But my ajax call not alowing external url .

can anyone explain how can we use external url with jq

相关标签:
7条回答
  • 2020-11-28 11:17

    I think the only way is by using internel PHP code like MANOJ and Fernando suggest.

    curl post/get in php file on your server --> call this php file with ajax

    The PHP file let say (fb.php):

    $commentdata=$_GET['commentdata'];
    $fbUrl="https://graph.facebook.com/16453004404_481759124404/comments?access_token=my_token";
    curl_setopt($ch, CURLOPT_URL,$fbUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    // POST data here
    curl_setopt($ch, CURLOPT_POSTFIELDS,
            "message=".$commentdata);
    
    // receive server response ...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $server_output = curl_exec ($ch);
    echo $server_output;
    curl_close ($ch);
    

    Than use AJAX GET to

    fb.php?commentmeta=your comment goes here
    

    from your server.

    Or do this with simple HTML and JavaScript from externel server:

    Message: <input type="text" id="message">
    <input type="submit" onclick='PostMessage()'>
    <script>
    function PostMessage() {
    var comment = document.getElementById('message').value;
        window.location.assign('http://yourdomain.tld/fb.php?commentmeta='+comment)
    }
    </script>
    
    0 讨论(0)
提交回复
热议问题