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

  • SEARCH
  • Home
  • 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 1111991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:38:13+00:00 2026-05-17T02:38:13+00:00

Within a jQuery ajax function data supplied to the callback function on success is

  • 0

Within a jQuery ajax function data supplied to the callback function on success is defined with

success: function (data) { ...

but this makes JSLint unhappy (“Don’t make functions within a loop”).

If I follow the suggestion in How to fix jslint error 'Don't make functions within a loop.'?, Firebug complains that “data is not defined” and the callback function fails.

Example:

Prior to $(document).ready(function(){

function ajaxSuccess() {
   return function (data) {
      alert (data);
   };
}

Within $(document).ready(function(){

$.ajax({
    type: "POST",
    url: "some-url-here",
    data: ({ "foo" : "bar" }),
    success: ajaxSuccess(data)
});

results in “data not defined” error.

But if I change it to

$.ajax({
    type: "POST",
    url: "some-url-here",
    data: ({ "foo" : "bar" }),
    success: function (data) {
        ajaxSuccess(data);
    }
});

then everything is hunky-dory — but now I’m back where I started as far as JSLint is concerned.

Assuming I want to pass muster with JSLint, how do I get ahold of data returned by url and pass it on to the function in question?

  • 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-17T02:38:13+00:00Added an answer on May 17, 2026 at 2:38 am

    success: needs a function, but you don’t have to create one just for it.

       function ajaxSuccess(data) 
       { 
         alert (data); 
       }
     // :
     // :
    
    $.ajax({ 
        type: "POST", 
        url: "some-url-here", 
        data: ({ "foo" : "bar" }), 
        success: ajaxSuccess     // note: no parameters, just the name.
        } 
    });   
    

    Originally, you were say “create a new function, which takes a data parmeter, and assign it to success“. My version says “I already have a function which takes a data parameter (named ajaxSuccess). Assign it to success”.

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

Sidebar

Related Questions

So I am grabbing this XML data, and parsing it within the success function
I'm trying to get the success data from a jquery Ajax call so I
I have a simple $.ajax({ url: someUrl, method: 'get', dataType: 'html', success: function(data) {
I have a simple ajax call: $.ajax({url: my_url_here, dataType: 'text', success: function(data, textStatus) {
I am trying to perform an ajax.get using jquery within document.ready . But the
I need to open a link from within jQuery but i need to avoid
I have about 40 links which are all handled within jquery but when they
Just wandering if it makes sense, to use if statements like below within jquery
I'm trying to get twitter bootstrap's .popover working within a .submit jquery event but
I'm trying to get a jsonp callback working using jquery within a greasemonkey script.

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.