uno
uno

Reputation: 867

Uncaught TypeError: response is not a function

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"}})

Upvotes: 3

Views: 21753

Answers (3)

Alexandr Lazarev
Alexandr Lazarev

Reputation: 12892

As 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.

Upvotes: 1

Karthikeyan Ganesan
Karthikeyan Ganesan

Reputation: 2035

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

Upvotes: 0

James Yang
James Yang

Reputation: 1416

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

Upvotes: 0

Related Questions