How can I debug ajax errors?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I debug ajax errors?

Mariano Martinez Peck
Hi guys,

It happens to me quite frequently that I have some issue in an AJAX calls. On Chrome, I see:

Uncaught SyntaxError: Unexpected token $ in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.n.parseJSON (jQuery.js:4)
    at HTMLDocument.<anonymous> (reps?_s=YZ0L_G1AYPiERSfd&_k=lD9O_xh3oh59qMMq:453)
    at HTMLDocument.dispatch (jQuery.js:3)
    at HTMLDocument.r.handle (jQuery.js:3)
    at Object.trigger (jQuery.js:3)
    at x (jQuery.js:4)
    at XMLHttpRequest.b (jQuery.js:4)

But there is no way for me to know what triggered that at Seaside level. If I inspect the "VM2043:1" kind of link in the Chrome console, I get to the script generated by my ajax which is something like:

$("#id174").replaceWith("<div class=\"companyReportMainDiv\" id=\"id232\"><div id=\"popupContainer9358488\" class=\"popupContainer\"></div><script
..........
)

Chrome shows me that with a red underline like if that would have an error, but such JS is correct. 

Any idea how can I know what is going on? 


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How can I debug ajax errors?

Mariano Martinez Peck


On Fri, Feb 10, 2017 at 5:02 PM, Mariano Martinez Peck <[hidden email]> wrote:
Hi guys,

It happens to me quite frequently that I have some issue in an AJAX calls. On Chrome, I see:

Uncaught SyntaxError: Unexpected token $ in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.n.parseJSON (jQuery.js:4)
    at HTMLDocument.<anonymous> (reps?_s=YZ0L_G1AYPiERSfd&_k=lD9O_xh3oh59qMMq:453)
    at HTMLDocument.dispatch (jQuery.js:3)
    at HTMLDocument.r.handle (jQuery.js:3)
    at Object.trigger (jQuery.js:3)
    at x (jQuery.js:4)
    at XMLHttpRequest.b (jQuery.js:4)

But there is no way for me to know what triggered that at Seaside level. If I inspect the "VM2043:1" kind of link in the Chrome console, I get to the script generated by my ajax which is something like:

$("#id174").replaceWith("<div class=\"companyReportMainDiv\" id=\"id232\"><div id=\"popupContainer9358488\" class=\"popupContainer\"></div><script
..........
)



OK, the JSON failure was due to my AJAX error handler, which was trying to do (see bold part)
 
                var requestResponse = {
   url: settings.url,
   method: settings.type,
   data: settings.data,
   httpStatus: jqxhr.status,
   error: exception || jqxhr.statusText,
   data: settings.data
 };

responseText = jqxhr.responseText;
responseText.replace(/[\\"'']/g, ''\\$&'').replace(/\u0000/g, ''\\0''); 
console.error(requestResponse);
jsonValue = jQuery.parseJSON(responseText);

I am now printint to console the requestResponse that was in this ajax error handler, and this is what I get:

  1. Object
    1. data:undefined
    2. error:SyntaxError: Unexpected token , at eval (<anonymous>) at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616 at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627) at n.fn.init.domManip (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:22515) at n.fn.init.replaceWith (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:21650) at eval (eval at <anonymous> (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616), <anonymous>:1:13) at eval (<anonymous>) at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616 at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627) at text script (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:4:26788)
      1. message:"Unexpected token ,"
      2. stack:"SyntaxError: Unexpected token ,↵ at eval (<anonymous>)↵ at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616↵ at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627)↵ at n.fn.init.domManip (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:22515)↵ at n.fn.init.replaceWith (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:21650)↵ at eval (eval at <anonymous> (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616), <anonymous>:1:13)↵ at eval (<anonymous>)↵ at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616↵ at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627)↵ at text script (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:4:26788)"
      3. __proto__:Error
    3. httpStatus:200
    4. method:"GET"
    5. url:"/reps?_s=YZ0L_G1AYPiERSfd&_k=-szkZv0x3mvWhG7t&193&203=VALE&206=1&207=&216=&221=&_=1486757530835"
    6. __proto__:Object





I don't understand what is going on. Any ideas?

Thanks in advance

 
Chrome shows me that with a red underline like if that would have an error, but such JS is correct. 

Any idea how can I know what is going on? 




--

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How can I debug ajax errors?

Johan Brichau-2
Hey Mariano,

There’s a syntax error somewhere.
Ok… that’s a lousy response, I know :)

Can you fetch the generated JS from the url and send that in a text file?
Just to be sure: is this happening with the result of a jQuery script callback?

It would be good to know what Seaside-JS code that is executing to generate the script you are sending.

Johan


I am now printint to console the requestResponse that was in this ajax error handler, and this is what I get:

  1. Object
    1. data:undefined
    2. error:SyntaxError: Unexpected token , at eval (<anonymous>) at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616 at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627) at n.fn.init.domManip (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:22515) at n.fn.init.replaceWith (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:21650) at eval (eval at <anonymous> (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616), <anonymous>:1:13) at eval (<anonymous>) at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616 at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627) at text script (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:4:26788)
      1. message:"Unexpected token ,"
      2. stack:"SyntaxError: Unexpected token ,↵ at eval (<anonymous>)↵ at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616↵ at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627)↵ at n.fn.init.domManip (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:22515)↵ at n.fn.init.replaceWith (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:3:21650)↵ at eval (eval at <anonymous> (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616), <anonymous>:1:13)↵ at eval (<anonymous>)↵ at https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2616↵ at Function.globalEval (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:2:2627)↵ at text script (https://debrisdemo.quuve.com/JQDeploymentLibrary/jQuery.js:4:26788)"
      3. __proto__:Error
    3. httpStatus:200
    4. method:"GET"
    5. url:"/reps?_s=YZ0L_G1AYPiERSfd&_k=-szkZv0x3mvWhG7t&193&203=VALE&206=1&207=&216=&221=&_=1486757530835"
    6. __proto__:Object





I don't understand what is going on. Any ideas?

Thanks in advance

 
Chrome shows me that with a red underline like if that would have an error, but such JS is correct. 

Any idea how can I know what is going on? 




-- 
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside