How to get values from data: part in ajax call
$.ajax({ type: "POST", url: baseUrl + "query?v=21266702", contentType: "application/json; charset=utf-8", dataType: "json", headers: { "Authorization": "Bearer " + accessToken
},
data: JSON.stringify({ query: text, lang: "en", sessionId: reqIdToken }),
success: function(data) {
xyz
}else{
setResponseForIT(data,"");
}
},
error: function() {
setResponse("Internal Server Error");
}
});
You would assign this stuff to variables before sending the raw data.
You have the data right here :
query: text, lang: "en", sessionId: reqIdToken
you are basically building the JSON on the fly, just process these before by setting them as variables.
Update (for clarification) :
This is creating json for you based on the variables already set etc.
JSON.stringify({ query: text, lang: "en", sessionId: reqIdToken })
This means you have access to 'text' and 'reqIdToken' and hence don't need to look at the 'data' variable that contains the json. Just use reqIdToken if you want to know the sessionId. (eg if (reqIdToken == "999") alert();)
链接地址: http://www.djcxy.com/p/96484.html