2013-03-13 55 views
0

在terinal我使用以下代碼得到一個交方法的輸出:使用URL containes餅乾在javascript

curl -X POST 'http://localhost:8787/rpc/getSingleSecurity' -d @data -H 'Cookie: user-id=algotree|Mon%C%2013%20Mar%2023%2009%3A48%3A16%20GMT|EVtpHw4dlEYCnrIxUQZORgJXvGk%3D' 

數據I具有如下:

{"method":"getSingleSecurity", "params":[{"ticker":"AAPL"} ], "clientId": "31d0c653-d7e5-44b6-98b5-8c084f99514a", "version":1354777632} 

輸出如下:

{"ep":"false","result":{"CUSIP":["037833100"],"name":["Apple Inc"],"ticker":["AAPL"]}} 

我想在JavaScript中使用輸出。我如何使用$ .ajax()方法使用此URL的輸出?

+0

是你的好幫手嗎? – 2013-03-13 12:43:54

+0

請檢查我的問題中的編輯。 – 2013-03-13 12:50:09

回答

1

查看下面的代碼片段,使用ajax進行發佈請求。您還可以按照下面的說明使用Cookie將其用於已認證的請求。

var cookie = $.cookie('yourCookieNameHere'); 
var reqUrl = requestUrl; 

jQuery.ajax({ 
    type: "POST", 
    url: reqUrl, 
    dataType: "json", 
    data: { 
     utf8: true, 
     _method:"POST", 
     "method":"getSingleSecurity", 
     "params":[{"ticker":"AAPL"} ], 
     "clientId": "31d0c653-d7e5-44b6-98b5-8c084f99514a", 
     "version":1354777632    //replace these with variables if any 
    }, 
    Cookie: cookie 
}).success(function (response, textStatus, jqXHR){ 
    // you can use response data from response 
    console.log("This is response data " + response); 
});