admin管理员组文章数量:1335887
I am trying to get the response of this url. But when I check the console error message appears:
Uncaught TypeError: response is not a function
What is the possible problem?
var uri = pbxApi+"/conference/participants/"+circle+"/"+data.conference+"/"+data.uniqueid+'?jsonp=response';
getJsonData(uri, function(res){
});
This is my function.
var getJsonData = function(uri,callback){
$.ajax({
type: "GET",
dataType: "jsonp",
url: uri,
jsonpCallback: 'response',
cache: false,
contentType: "application/json",
success: function(json){
callback(json);
}
});
}
this is my response:
response({"_id":"56177d3b3f2dc8146bd8565c","event":"ConfbridgeJoin","channel":"SIP/192.168.236.15-0000005e","uniqueid":"1444379955.224","conference":"0090000293","calleridnum":"0090000290","calleridname":"0090000290","__v":0,"status":false,"sipSetting":{"accountcode":"0302150000","accountcode_naisen":"203","extentype":0,"extenrealname":"UID3","name":"0090000290","secret":"Myojyo42_f","username":"0090000290","context":"innercall_xdigit","gid":101,"cid":"0090000018"}})
I am trying to get the response of this url. But when I check the console error message appears:
Uncaught TypeError: response is not a function
What is the possible problem?
var uri = pbxApi+"/conference/participants/"+circle+"/"+data.conference+"/"+data.uniqueid+'?jsonp=response';
getJsonData(uri, function(res){
});
This is my function.
var getJsonData = function(uri,callback){
$.ajax({
type: "GET",
dataType: "jsonp",
url: uri,
jsonpCallback: 'response',
cache: false,
contentType: "application/json",
success: function(json){
callback(json);
}
});
}
this is my response:
response({"_id":"56177d3b3f2dc8146bd8565c","event":"ConfbridgeJoin","channel":"SIP/192.168.236.15-0000005e","uniqueid":"1444379955.224","conference":"0090000293","calleridnum":"0090000290","calleridname":"0090000290","__v":0,"status":false,"sipSetting":{"accountcode":"0302150000","accountcode_naisen":"203","extentype":0,"extenrealname":"UID3","name":"0090000290","secret":"Myojyo42_f","username":"0090000290","context":"innercall_xdigit","gid":101,"cid":"0090000018"}})
Share
Improve this question
edited Oct 14, 2015 at 7:42
Alexandr Lazarev
12.9k4 gold badges39 silver badges47 bronze badges
asked Oct 14, 2015 at 5:24
unouno
8672 gold badges16 silver badges30 bronze badges
4
- 1 check this one stackoverflow./questions/32450690/… – guradio Commented Oct 14, 2015 at 5:26
-
i already declared
jsonpCallback: 'response',
on my code. – uno Commented Oct 14, 2015 at 5:30 -
Just to mention,
success: function(json){ callback(json); }
is renundat, you can simply usesuccess: callback(json)
– Alexandr Lazarev Commented Oct 14, 2015 at 5:53 -
if i use this
success: callback(json)
instead of thissuccess: function(json){ callback(json); }
json will be undefine – uno Commented Oct 14, 2015 at 6:24
3 Answers
Reset to default 1As it is written here:
jsonpCallback Type: String or Function() Specify the callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. As of jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback is set to the return value of that function.
So by setting jsonpCallback
property of your ajax object, you are passing a name of a function (or a function itself from jQuery 1.5) that should be treated as a callback. That means that if you set its value to 'response'
, a response()
function should be declared.
Working example:
// first declare you function
function response(obj){console.log(obj)};
$.ajax({
url:'http://www.mocky.io/v2/561dedcb1000002811f142e5',
dataType:'jsonp',
jsonp:false, // make it to false, to use your function on JSON RESPONSE
jsonpCallback: 'response',
success: function(ret){
console.log('ok');
}
});
setup a demo here
just use this type of coding for return your callback data.
function getJsonData(uri,callback)
{
$.ajax({
type: "GET",
dataType: "json",
url: uri,
cache: false,
success: function(json){
callback(json);
}
});
}
getJsonData(function(resp)
{
console.log(resp);
}
Now you got the return data in console.log
本文标签: javascriptUncaught TypeError response is not a functionStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: response is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742397395a2467200.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论