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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:51:50+00:00 2026-05-30T11:51:50+00:00

Im using the following ajax code to submit data from a form to a

  • 0

Im using the following ajax code to submit data from a form to a servlet and then have the servlet send data back (havent quite mastered this part yet).

Side question, the variable id is obtained from the .jsp file by using

`<script> var id = '${id}' </script>`

Is there a better way to access this variable directly from inside a .js file that is loaded on the page ? It works as is but it seems messy.

$(document).ready(function () {
    $('.doAction').click(function () {
        var rel = parseInt($('.doAction:checked').attr('rel'));
        $.ajax({
            type: 'POST',
            dataType: 'json',
            cache: false,
            data: {
                rating: rel,
                itemID: id
            },
            url: 'Ratings',
            success: function (data) {

            }
        });
    });
});

The HTML form code is

<div id=holder>
    <div id="rating">
    Rating
        <form id="ratingsform" name="ratingsform">
            <input class="doAction" type="radio" name="ra1" rel="1" />
            <input class="doAction" type="radio" name="ra1" rel="2" />
            <input class="doAction" type="radio" name="ra1" rel="3" />
            <input class="doAction" type="radio" name="ra1" rel="4" />
            <input class="doAction" type="radio" name="ra1" rel="5" />
        </form>
    </div>
</div>

So what i want to happen is when a radio button is selected, the form is disabled so that new radio buttons can’t be pressed (so the servlet cant be spammed to death). When the servlet responds to the ajax post call, I would like to change the contents of the div “rating” to display the updated ratings and remove the ability to vote i.e remove the radio buttons / form. I have the server side code working except for figuring out how to return the values required which hopefully is pretty straight forward.

Any suggestions ?

  • 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-30T11:51:51+00:00Added an answer on May 30, 2026 at 11:51 am

    well check my comments to understand the change

    $(document).ready(function () {
    
        var id = '${id}' // you can have it here
        $('.doAction').click(function () {
            var rel = $('.doAction:checked').attr('rel'); // you need not parse to int because it will always string in parameter
            $('.doAction').prop('disabled', true); // to disable radio button
            $.ajax({
                type: 'POST',
                dataType: 'html', // change this since your servlet response is html not json
                cache: false,
                data: {
                    rating: rel,
                    itemID: id
                },
                url: 'Ratings',
                success: function (data) {
                       $('#rating').html(data); // assuming response as {"rating" : 4.4} 
                }
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following block of code: $(document).ready(function(){ $(#form).submit(function(ev) { ev.preventDefault(); $.ajax({ type: POST,
I am successfully posting a form via ajax, using the following code; $.post( Page.do?source=ajax,
i'm using the following code to submit a form: function submitfilter(){ alert(in here); var
I've got the following code: <script type=text/javascript> $(function(){ $(#AddMaps).submit(function(){ var $form = $('#AddMaps'); $.ajax({
I have a the following code @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = update_panel, Url
I have the following code but when I submit the from the page redirects.
I have an HTML form using dojo and have the following code for a
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
In the following code, I'm using Ajax.BeginForm to post data to the action asynchronously.
I am trying to use link to submit a form using the following code:

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.