I am making HTTP requests to a web service that requires authentication. My intiial request is as follows:
function getReq() {
$.ajax( {
type: "GET",
url: urlRequest,
dataType: jsonp,
cache: false,
// success: getRates,
error: onFaultAjaxRequest,
timeout: DEFAULT_TIMEOUT_AJAX_REQUEST
});
}
The urlRequest contains the base address plus a querystring with my username and password. The HTTP response resulting in this request includes a session ID. This session ID is used in subsequent HTTP requests to the web service.
How do I trap the session ID using JQuery or another alternative method?
When I receive the second response with my currency data, how do I utilize JQuery CSV plugin to create an array from the data returned in CSV format?
Thanks, Sid
Edit Based on responses thus far, here's what I have written for my js file:
var urlRequest = "http://webrates.truefx.com/rates/connect.html?u=user&p=pass&f=html&q=dfrates"
var DEFAULT_TIMEOUT_AJAX_REQUEST = 33000; //in milisecond
var DEFAULT_TIMEOUT_AFTER_SUCCESS_REQUEST = 330; //time after succes request before next request
function getReq() {
$.ajax( {
type: "GET",
url: urlRequest,
dataType: jsonp,
cache: false,
success: getRates,
beforeSend: function(xhr){
xhr.withCredentials=true;
},
error: onFaultAjaxRequest,
timeout: DEFAULT_TIMEOUT_AJAX_REQUEST
});
}
function getRates(){
var tab=jXHR.getAllResponseHeaders();
}
function onFaultAjaxRequest(XMLHttpRequest, textStatus, errorThrown) {
var t = setTimeout(getReq, DEFAULT_TIMEOUT_AFTER_SUCCESS_REQUEST);
}
function onSuccessAjaxRequest(returnData) {
var obj= getReq;
var arr=$.makearray(obj);
};
My index.html page is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to MyDomain.com</title>
<script type="text/javascript" src="dist/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="dist/jquery.jqplot.js"></script>
<script type="text/javascript" src="js/dfc.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.jqplot('chartdiv'[onSuccessAjaxRequest]);
});
</script>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="chartdiv">
</div>
</body>
</html>
When I debug ind开发者_Python百科ex.html, I receive an error stating JScript error "No Data Specified" in the jqplot plugin. How should I remedy this situation?
Thanks much!!
I thought about something like this:
function getReq() {
$.ajax( {
type: "GET",
url: urlRequest,
dataType: jsonp,
cache: false,
success: getRates,
beforeSend: function(xhr){
xhr.withCredentials = true;
},
error: onFaultAjaxRequest,
timeout: DEFAULT_TIMEOUT_AJAX_REQUEST
});
}
function getRates(data, textStatus, jXHR) {
var tab=jXHR.getAllResponseHeaders();
// tab is a string with headers ...
}
However, there are cross-domain and browser issues. For examle, firefox 3.5 (or jquery) seems to clear Set-Cookie field, so it's empty in javaScript. When connecting to other domain, xhr.withCredentials=true has to be set also.
Check this out $("div#data).data("UID",UID)
to store the session id.
http://forum.jquery.com/topic/data-session-variable-or-cookie. Personally I never used session IDs in client side because sessions IDs are part of url and not the query string, in java see JSESSIONID, see where the question mark ?
is in url. It is after sessionid. You dont have to handle it browsers will send it when session will be established.
精彩评论