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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:07:17+00:00 2026-06-14T14:07:17+00:00

I have some question about a JQuery script (I am new in JQuery world):

  • 0

I have some question about a JQuery script (I am new in JQuery world):

In a view page I have the following link:

        <li>
            <a id="byHeader" href="<c:url value="/mapping/header" />">By presence of header</a>
        </li>

So clicking on this link I generate an HTTP Request towards “/mapping/header” folder.

Now in the view page I have also the following JQuery code related to the previus links:

$("#byHeader").click(function(){    // Select the link having id="byHeader" and  assign to it the following callback function executed on the click event
    var link = $(this);             // Variable refered to the link tag that triggered the event

    /* La chiamata AJAX non viene invocata su un oggetto particolare (quindi direttamente su $)
       I parametri di input sono: 1) L'URL del link selezionato 2) Il tipo di risposta previso (una stringa)
    */
    $.ajax({ url: this.href, dataType: "text", 
        // Before sending the HTTP Request: execute a function that add an Header to this HTTP Request
        beforeSend: function(req) { req.setRequestHeader("FooHeader", "foo"); }, 
        // Success case:
        success: function(form) { 
            MvcUtil.showSuccessResponse(form, link); 
        }, 
        // Error case:
        error: function(xhr) { 
            MvcUtil.showErrorResponse(xhr.responseText, link); 
        }
    });
    return false;
});

Probably my doubts are trivial and depend on my lack of knowledge of JQuery…

1) The first dount regard the req variable in this line of code:

        beforeSend: function(req) { req.setRequestHeader("FooHeader", "foo"); },

By this line of code I think that I am adding an headers to my HTTP Request to send it towards the server.

My problem is understand what it points the variable named “req”. I think that this is referred to my HTTP Request but my problem is that I never declared it before…I am using it (and it work well) without ever having declared it in the code before !!! Why it work?

I am thinking that when I use the beforeSend it create automatically a parameter variabile that contain the reference to the HTTP Request for my function…but…finally I don’t know if it is right…

2) The second doubt regard these lines of code:

        success: function(form) { 
            MvcUtil.showSuccessResponse(form, link); 
        }, 

these code lines handle the succes case (the case in which the script is able to append the header to the HTTP Request)…

Reading the JQuery succes api documentation I have understand that the success method (is it a method? right?) accept as parametr the data returned from the server…

As you can see in the code, the server returns to the client a text string (infact I have: dataType: “text”)…so…why in the previus code lines the parameter is named “form”?

the server return to the client a text, not a “form”…I’m missing something?

And…also in this case: I have not created the form variabile, is it a “generic” variable that contains the data returned by the server and I can use it because in the previus line I have use the JSON format in the ajax call?

Thank you very much

Andrea

  • 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-14T14:07:19+00:00Added an answer on June 14, 2026 at 2:07 pm
    1. The jQuery ajax system creates req for you and pass it as a parameter for your callback.

    2. Dunno, just a weird name for a varable… You are correct, if your dataType is text, the result will come as a plain string.

      As for you not creating the variable, again the data returned (in this case a string) is created by jQuery and just passed as a parameter for your callback.

    You seem to be confused by the concepts of "variable" and "function parameter". I’d suggest reading more about "global variables" and "variable scope". In short, req and form are only available from inside those functions, code outside them won’t have access to it. OTOH if you declare a variable like var x somewhere, every code in the same scope will have access to it (if you declare it outside any function, it will be a global, so all your code can access it).

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

Sidebar

Related Questions

I have a question about some functionality I'm trying to add to my jQuery
I'm working on some JQuery code and I have a question about caching selectors.
I have quick question about jQuery plugins, hope somebody out there has some advice.
I have some question about jquery selection. In my case, how to match if
I have some question about WH_MOUSE. From what I've read, by putting the hook
So, i have some question about xml Documents in Java. Can i get all
I have a question about reflection I am trying to have some kind of
Quick question about include/requre_once . I have some code that is common to a
i have what i hope is a quick question about some code i am
I have a question about SqlDataReader: Is there some way to modificated the values

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.