如何使用jquery将json变量访问到另一个json?
我想将第一个json变量访问到第二个json url如何使用jquery将json变量访问到另一个json?,jquery,json,Jquery,Json,我想将第一个json变量访问到第二个json url var responce_code; $.getJSON(url, function(data) { responce_code = (data.etsy_response_code); } $.getJSON("<?=base_url()?>etsy/getListing/responce_code", function(data) { } var响应_码
var responce_code;
$.getJSON(url, function(data) {
responce_code = (data.etsy_response_code);
}
$.getJSON("<?=base_url()?>etsy/getListing/responce_code", function(data) {
}
var响应_码;
$.getJSON(url、函数(数据){
response_code=(data.etsy_response_code);
}
$.getJSON(“etsy/getListing/response_code”,函数(数据){
}
var responce\u代码;
$.getJSON(url、函数(数据){
response_code=(data.etsy_response_code);
$.getJSON(“etsy/getListing/”+response_代码,函数(数据){
});
});
var responce\u代码;
$.getJSON(url、函数(数据){
response_code=(data.etsy_response_code);
$.getJSON(“etsy/getListing/”+response_代码,函数(数据){
});
});
有两件事需要改变:
getJSON
是异步的,所以您必须将第二个请求嵌套在第一个请求中。否则,第二个请求可能会在第一个请求完成之前启动,因此您的response\u code
仍然是emtpy$.getJSON(url, function(data) {
var responce_code = (data.etsy_response_code);
$.getJSON("<?=base_url()?>etsy/getListing/" + responce_code, function() {
// second callback
});
});
$.getJSON(url、函数(数据){
var response_code=(data.etsy_response_code);
$.getJSON(“etsy/getListing/”+response_代码,函数(){
//第二次回调
});
});
有两件事需要改变:
getJSON
是异步的,所以您必须将第二个请求嵌套在第一个请求中。否则,第二个请求可能会在第一个请求完成之前启动,因此您的response\u code
仍然是emtpy$.getJSON(url, function(data) {
var responce_code = (data.etsy_response_code);
$.getJSON("<?=base_url()?>etsy/getListing/" + responce_code, function() {
// second callback
});
});
$.getJSON(url、函数(数据){
var response_code=(data.etsy_response_code);
$.getJSON(“etsy/getListing/”+response_代码,函数(){
//第二次回调
});
});
您必须在第一次调用的回调
函数中执行第二次$.getJSON
。这是一个ajax
GET调用。请按以下方式执行:
var responce_code;
$.getJSON(url, function(data) {
//success callback
responce_code = (data.etsy_response_code);
$.getJSON("<?=base_url()?>etsy/getListing/responce_code", function(data) {
//2nd call success callback
});
});
var响应_码;
$.getJSON(url、函数(数据){
//成功回调
response_code=(data.etsy_response_code);
$.getJSON(“etsy/getListing/response_code”,函数(数据){
//第二次呼叫成功回调
});
});
您必须在第一次调用的回调
函数中执行第二次$.getJSON
。这是一个ajax
GET调用。请按以下方式执行:
var responce_code;
$.getJSON(url, function(data) {
//success callback
responce_code = (data.etsy_response_code);
$.getJSON("<?=base_url()?>etsy/getListing/responce_code", function(data) {
//2nd call success callback
});
});
var响应_码;
$.getJSON(url、函数(数据){
//成功回调
response_code=(data.etsy_response_code);
$.getJSON(“etsy/getListing/response_code”,函数(数据){
//第二次呼叫成功回调
});
});
也许这就是你需要的
改用AJAX
var response= $.ajax({
type: "POST",
dataType: "json",
async: false,
url:"Your Url"
})
var data = JSON.parse(response.ResponseText)
$.getJSON("<?=base_url()?>etsy/getListing/"+data.responce_code , function(data) {
}
var响应=$.ajax({
类型:“POST”,
数据类型:“json”,
async:false,
url:“您的url”
})
var data=JSON.parse(response.ResponseText)
$.getJSON(“etsy/getListing/”+data.response_代码,函数(数据){
}
如果有帮助,请标记为答案。这可能是你需要的 改用AJAX
var response= $.ajax({
type: "POST",
dataType: "json",
async: false,
url:"Your Url"
})
var data = JSON.parse(response.ResponseText)
$.getJSON("<?=base_url()?>etsy/getListing/"+data.responce_code , function(data) {
}
var响应=$.ajax({
类型:“POST”,
数据类型:“json”,
async:false,
url:“您的url”
})
var data=JSON.parse(response.ResponseText)
$.getJSON(“etsy/getListing/”+data.response_代码,函数(数据){
}
如果有帮助,则标记为应答sir使用seprate函数not in function不重要,您仍然需要嵌套调用或确保一个调用未在另一个finisheds之前调用。ir使用seprate函数not in function不重要,您仍然需要嵌套调用或确保一个调用未在另一个finisheddi之前调用想要在selerate json函数中不包含函数您必须在回调中工作,否则您无法处理它。必须先执行第一个请求,然后才能启动第二个请求,否则变量
response\u code
没有内容,第二个请求将失败。我想要在Selrate json函数中不包含函数您必须在回调中工作,否则您无法处理它。必须先执行第一个请求,然后才能启动第二个请求,否则变量responce\u code
没有内容,第二个请求将失败。有人可以添加答案错误的原因,而不是向下投票。这样用户可以从失败中吸取教训。而不是向下投票投票给某人可以添加答案错误的原因,这样用户就可以从失败中吸取教训。