ajax jquery simple get request

前端 未结 5 2061
天命终不由人
天命终不由人 2021-02-03 23:31

I am making this simple get request using jquery ajax:

$.ajax({
    url: \"https://app.asana.com/-/api/0.1/workspaces/\",
    type: \'GET\',
    success: functio         


        
相关标签:
5条回答
  • 2021-02-03 23:31

    i think the problem is that there is no data in the success-function because the request breaks up with an 401 error in your case and thus has no success.

    if you use

    $.ajax({
            url: "https://app.asana.com/-/api/0.1/workspaces/",
            type: 'GET',
             error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
      }
        });
    

    there will be your 401 code i think (this link says so)

    0 讨论(0)
  • 2021-02-03 23:34
    var settings = {
            "async": true,
            "crossDomain": true,
            "url": "<your URL Here>",
            "method": "GET",
            "headers": {
                "content-type": "application/x-www-form-urlencoded"
            },
            "data": {
                "username": "user@company.com",
                "password": "12345678"
            }
        }
    
        $.ajax(settings).done(function (response) {
            console.log(response);
        });
    
    0 讨论(0)
  • 2021-02-03 23:38

    It seems to me, this is a cross-domain issue since you're not allowed to make a request to a different domain.

    You have to find solutions to this problem: - Use a proxy script, running on your server that will forward your request and will handle the response sending it to the browser Or - The service you're making the request should have JSONP support. This is a cross-domain technique. You might want to read this http://en.wikipedia.org/wiki/JSONP

    0 讨论(0)
  • 2021-02-03 23:54

    You can make AJAX requests to applications loaded from the SAME domain and SAME port.

    Besides that, you should add dataType JSON if you want the result to be deserialized automatically.

    $.ajax({
            url: "https://app.asana.com/-/api/0.1/workspaces/",
            type: 'GET',
            dataType: 'json', // added data type
            success: function(res) {
                console.log(res);
                alert(res);
            }
        });
    

    http://api.jquery.com/jQuery.ajax/

    0 讨论(0)
  • 2021-02-03 23:56
    var dataString = "flag=fetchmediaaudio&id="+id;
    
    $.ajax
    ({
      type: "POST",
      url: "ajax.php",
      data: dataString,
      success: function(html)
      {
         alert(html);
      }
    });
    
    0 讨论(0)
提交回复
热议问题