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 6950103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:03:06+00:00 2026-05-27T14:03:06+00:00

Options of how I want to call a function: myAjax(http://ajaxurl.com, { prop: val },

  • 0

Options of how I want to call a function:

myAjax("http://ajaxurl.com", { prop: val }, function(resp) { alert(resp); });

or

function handleSuccess(resp) { alert(resp); }
myAjax("http://ajaxurl.com", { prop: val }, handleSuccess);

or

myAjax("http://ajaxurl.com", { prop: val }, null);

or

myAjax("http://ajaxurl.com", { prop: val }); // param not even provided

How can I handle this on the myAjax function definition? Something like this…?

function myAjax(url, jsonData, successFunc) {
  $.ajax({
    ... all the necessary ajax stuff that normally goes here
    , success: function(response) {
      // custom myAjax success handling goes here. this must happen before optionally-passed-in successFunc gets executed

      // what goes here? this?
      if (typeof successFunc != 'undefined' && successFunc != null) {
        successFunc(response);
      }
    }
  });
}

I tried something like the above, but, it did not call the success function. Do I need to check if successFunc is a function?

Thanks!

  • 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-05-27T14:03:07+00:00Added an answer on May 27, 2026 at 2:03 pm

    Instead of testing against unknown types, verify that the function is indeed a function:

    if (typeof successFunc == 'function') {
        successFunc(response);
    }
    

    Your current code does not prevent successFunc from being run, though. Make sure that the AJAX request is successfully handled (no errors no cross-domain restrictions).

    Since your code doesn’t event reach the point of calling successFunc, it’s likely that an error is generated before if (typeof ....

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

Sidebar

Related Questions

I want to use the fcbk_autocomplete function I downloaded from http://www.emposha.com/javascript/fcbkcomplete.html in Google Maps
i am new to objective c programming I want to call a function within
I have made a jQuery function and want to call it on click event.
Basic PHP function: //SOAP CALL function sayHello(){ $client = new SoapClient('http://Server:8080/MyClassService/MyClass?WSDL'); $response = $client->glassfishHello();
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js type=text/javascript></script> <script> $.get(http://example.com/, function(data) { alert(data); }); </script> it does an OPTIONS
I want to call this function (makes an element to blink), declared as a
I want to call removeSomething() (see in line 9) internally: JS-Code is: (function($){ $.fn.extend({
I want to call editObject() inside of my jQuery function, the initalisation call does
I am using Jquery tiptip plugin. I want to call deactive_tiptip function with clicking
I have written a jQuery plugin which I want to call a custom function

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.