Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:29:13+00:00 2026-06-14T08:29:13+00:00

I have this jsonp function: function jsonp(url, callback) { var script = document.createElement(script); script.setAttribute(type,text/javascript);

  • 0

I have this jsonp function:

    function jsonp(url, callback) {
    var script = document.createElement("script");
    script.setAttribute("type","text/javascript");
    script.setAttribute("onerror","javascript:DisplayPopUp('','staleExceptionRefresh')");
    script.setAttribute("src", url + questionMark + "accept=jsonp&callback="+callback + "&cachebuster="+new Date().getTime());
    document.getElementsByTagName("head")[0].appendChild(script);
}

I catch the success event like this:

function someCallbackFunction(data1, data2) {}

but the problem is that if I get 404 or 409 or some other server errors I don’t know how to catch them (they do not appear on someCallbackFunction).

I can set an onerror attribute to display something but how do I catch the server’s response.

this is an example for a server response that I am not able to catch with my regular callback function:

DeleteWebsiteAjaxCall({"action":"", "type":"", "callerId":""}, {errorDescription: "important description I want to display","success":false,"payload":null});

How do I catch these errors (stale exceptions?!) on a function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:29:14+00:00Added an answer on June 14, 2026 at 8:29 am
    function jsonp(url, callback) {
        var script = document.createElement("script");
        script.setAttribute("type","text/javascript");
        script.setAttribute("src", url + questionMark + "accept=jsonp&callback="+callback + "&cachebuster="+new Date().getTime());
        var errHandler = function(evt) {
          clearTimeout(timer)
          // reference to http://www.quirksmode.org/dom/events/error.html
          // you will get an error eventually, and you can call callback manually here, to acknowledge it.
          // but unfortunately, on firefox you can get error type as undefined, and no further detail like error code on other browser either. 
          // And you can tell the callback function there is a net error (as no other error will fire this event.)
          window[callback](new Error());
        };
        script.onerror = errHandler;
        script.onload = function() {
          clearTimeout(timer);
        }
        // also setup a timeout in case the onerror failed.
        document.getElementsByTagName("head")[0].appendChild(script);
        var timer = setTimeout(errHandler, 5000);
    }
    

    If your server will response when 404/409 happens, then send the 200 status code to client instead to make the script being evaluated.

    Otherwise, the browser will omit the server response and fire onerror event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Javascript Ajax: <script type=text/javascript src=http://www.MyFirstDomain.com/jquery.js></script> <script type=text/javascript> $(document).ready( function () { var referrer =
I have a jQuery AJAX function like this: $.ajax({ url: 'crud/clients.php', dataType: 'json', type:
I have the following js snippet: <script language=javascript> function test() { this.a = 10;
I have no idea how to properly 'return' this JSON object (in JavaScript): function
Basically I have been using this function to achieve cross domain JSONP but part
Inside my .aspx I have some JSON code that looks like this: function someFunctionName()
Below is my code var tweetid = '133450847156838400'; $.ajax({ dataType: jsonp, url: http://api.twitter.com/1/statuses/show/+tweetid+.json?include_entities=1&callback=?, error:function(xhr,
I have the following function which works great, i used JSONP to overcome cross-domain,
I have a javascript function which asks for some ajax data and gets back
The following code: jQuery(document).ready(function($) { function getBooks() { var query = ajax.php?do=allbooks; $.ajax({ dataType:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.