0

I am trying to get some details from an external page with ana ajax request. Since i am getting back a answer from the server it seems for me the request is working fine, in the console i can even find the required information. My code is however giving me an error and a cant figure out why, can someone help? See Image where Error occurs after response!

enter image description here

This is the code is use to get the requested by ajax:

        var auth_id = "xxxxxxxxxxxxxxxx";
        var auth_token = "xxxxxxxxxxxxxxxx";
        var jSON_Object = {
            'auth_id': auth_id,
            'auth_token': auth_token
        };
        var calluuid = null;
        //Anruf aufnehmen
        function RecordTheCall() {
            var result = null;
            var post = $.ajax({
                url: "https://api.plivo.com/v1/Account/"+auth_id+"/Call/?status=live",
                type: "GET",
                dataType: "jsonp",
                contentType: "application/json",
                jsonCallback: "parseResponse",
                data: JSON.stringify(jSON_Object),
                success: function(res) {
                    console.log("1");
                    console.log(res);
                    //get uuid from active call
                    calluuid = res.call_uuid;
                    RecordIt();                     
                },
                error: function(err){
                    console.log("E1");
                    console.log(err);
                }
            });
        }
jhon dano
  • 660
  • 6
  • 23
  • It'd really help if you said what line was producing the error. Also there's the time-tested approach to fixing this by deleting stuff until the error goes away, then incrementally adding things back until you find the specific problem. Your variable called `jSON_Object` is making me eye-twitch, too. Why the lower-case `j`? – tadman May 25 '15 at 17:54
  • I am not getting syntax error, I guess that it's produced after response. – 8f7ca04d817b1696 May 25 '15 at 17:56
  • 1
    Are you sure server returns jsonp, not json? – A. Wolff May 25 '15 at 18:03
  • Servers return json, but when i change the dataType to json i get this error: No 'Access-Control-Allow-Origin' – jhon dano May 25 '15 at 18:08
  • Related: [No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access](http://stackoverflow.com/questions/20433655/no-access-control-allow-origin-header-is-present-on-the-requested-resource-or) The service has to offer support for JSONP or CORS for the request to be allowed [cross-origin](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy). If they don't offer either, or haven't given permission to your application, the request won't be possible client-side. – Jonathan Lonowski May 25 '15 at 18:38
  • see image attached... reponse is comming back from server but for some reason ends up in an syntax error! – jhon dano May 25 '15 at 18:44
  • @jhondano The response doesn't include the "*padding*" required by [JSON-P](http://json-p.org/). The service either expects a different parameter name than jQuery's default of `callback=...` or doesn't support the format outright. And, to request it as `dataType: "json"`, your application will need to be permitted by Plivo to make the request client-side. – Jonathan Lonowski May 25 '15 at 18:50

0 Answers0