3

i have $.ajax method like this

<form class="hidden code-box" method="GET" name="sample">
<div dir="ltr"><textarea class="php" name="codeguru"></textarea></div>
<div class="hint">This code is editable. Click Run to execute.</div>
<input type="submit" value="Run" />
<img class="hidden" style="vertical-align: middle;" alt="Try PHP  " src="http://code.guru99.com/img/ajax-loader.gif" name="ajax-loader" title="Try PHP " />
<div class="hidden stdout"></div>
<div class="hidden stderr"></div>
</form>

$.ajax({
            type: 'GET',
            url: '/exec.php',
            dataType: 'JSONP',
            data: {code : code},
            success: function(data) 
            {
                //alert(data.result);
                var data = data.result;
                $(loader).addClass('hidden');
                var stdout = $(form).children('.stdout');
                if (data.search("Parse error")>0)
                {
                    var str = data.replace('<b>Parse error</b>:  ','');
                    $(stdout).html(str);
                    $(stdout).removeClass('hidden');    
                }   
                else
                {
                    $(stdout).html(data);
                    $(stdout).removeClass('hidden');
                }   
            },
            jsonpCallback: 'mycallback',
            error: function (xhr, ajaxOptions, thrownError,err,textStatus) {
                var stdout = $(form).children('.stdout');
                alert (stdout);
                $stdout.html("Fatal error generated!!! Please check your code");
                $stdout.removeclass('hidden');
            }
        });

Now i want to print the error generated because of $.ajax method. and i have tried this.

error: function (xhr, ajaxOptions, thrownError,err,textStatus) {
                    var stdout = $(form).children('.stdout');
                    alert (stdout);
                    $stdout.html("Fatal error generated!!! Please check your code");
                    $stdout.removeclass('hidden');
                }

Please help

  • possible duplicate of [Parsing JSONP Response in Javascript when 4xx or 5xx Http Error Code is Present](http://stackoverflow.com/questions/5334413/parsing-jsonp-response-in-javascript-when-4xx-or-5xx-http-error-code-is-present) – Quentin Dec 16 '13 at 10:19
  • This is not duplicate sir –  Dec 16 '13 at 10:22

2 Answers2

3

Try this:

$( document ).ajaxError(function( event, request, settings ) {
console.log(settings.url);
});

or

$.ajax({
            type: 'GET',
            url: '/exec.php',
            dataType: 'JSONP',
            data: {code : code},
            success: function(data) 
            {
            },
            error: function(ts) { console.log(ts.responseText) }
});
Mr.G
  • 3,413
  • 2
  • 16
  • 20
0

well you don't need $ in stdout since it is already a jquery object..

try this

 error: function (xhr, ajaxOptions, thrownError,err,textStatus) {
            var stdout = $(form).children('.stdout'); //here stdout is jquery object
            alert (stdout);
            stdout.html("Fatal error generated!!! Please check your code"); 
       //--^---notice missing $ here
            stdout.removeClass('hidden');
            //-----------^----- here notice uppercase `C`
 }
bipen
  • 36,319
  • 9
  • 49
  • 62
  • with your code firefox shows this error - TypeError: stdout.removeclass is not a function stdout.removeclass('hidden'); –  Dec 16 '13 at 11:34
  • well yes that is because you have a typo `remoceclass` is actually `.removeClass()` – bipen Dec 16 '13 at 11:36
  • `C` should be uppercase in `removeClass()` you are getting that error because you have a lowercase `c` there.. did u notice .. check my answer again.. i updated it?? – bipen Dec 16 '13 at 11:39