Send JSON by cURL always returns “No access”

前端 未结 2 1047
遇见更好的自我
遇见更好的自我 2021-01-22 04:16

I have this JSON data:

$.ajax({
    type: \"GET\",
    url: \"http://www.example.com/test.php\",
    data:\"code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b         


        
相关标签:
2条回答
  • 2021-01-22 04:45

    First check http://www.example.com/test.php

    Ajax system can't be used with full domain name.

    so you should use /test.php

    Then checking for an error that occurs in your site or target site.

    Then the code becomes:

    $.ajax({
        type: "GET",
        url: "/test.php",
        data:"code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b",
        contentType: "application/json; charset=utf-8",
        success: function(data, textStatus) {   
            alert(data);
            data = $.parseJSON(data);
        },
        error : function(data, textStatus, error){                  
            alert(data + "  : "+ textStatus);
        }
    });
    
    0 讨论(0)
  • 2021-01-22 04:48

    Without the documentation to look out the only thing I can suggest is to remove the data from the array and just make it key code.

    <?php
    
    //API URL
    $url = 'http://www.example.com/test.php';
    $data = "?code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b"
    
    //Initiate cURL.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url . $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    //Execute the request
    $result = curl_exec($ch);
    
    ?>
    
    0 讨论(0)
提交回复
热议问题