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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:10:18+00:00 2026-05-25T23:10:18+00:00

I have no previous experience with Javascript/JQuery/AJAX and I was given a task on

  • 0

I have no previous experience with Javascript/JQuery/AJAX and I was given a task on our current project at my internship that relies heavily on all three! Our client has a site where users create profiles, but apparently a lot of users leave the page or refresh before they save the form and everything gets deleted.

I am supposed to make it so every time a user changes focus from the text area they are using, the text they have entered so far saves and is reloaded when they refresh the page, or whatever they are doing to lose everything. From what I have been told I need to make a JQuery function that does an AJAX post and then get, but I have no idea how to implement Javascript/JQuery/AJAX into HAML and Rails projects, let alone how to use any of the JS that I’m supposed to.

I realize not all the information needed to completely solve the problem is given here, I’ll happily supply that if someone asks, but I thought it would be best to just implement an alert function when the textarea loses focus and start small.

Thanks in advance!


*Revision #1


Okay, I filled in what Tejs gave me and have:

:javascript
  function post_text() {
    $(document).ready(function() {
      $.ajax({ 
        var currentTextBoxValue = $(textarea).val();
        var currentStatus = $(input).val();

        type: 'POST',
        url: '/profiles/:profile_id/profile_acts',
        data: ''
        success: function() {
          alert("Hello");
        }
      });
    });
  }

I currently have this at the bottom on the page and have {:onblur => "post_text()"} attached to the text_area_tag I want to get the data from. I got the URL from rake routes and I know that the data should be sent in JSON. I know that I need to send some JSON, but I need to include the profile_act_id's and don’t want to write a script for each act that we have and I’m not sure how I could incorporate Ruby class variables within the code.

As for what needs to be sent with JSON, I know that it needs to be something like this:

profile_acts:{"profile_act_40":{
  "act_id":"40", 
  "additional_info":currentTextBoxValue, 
  "status":currentStatus
  }
}

Ideally it would be something like this:

profile_acts:{"profile_act_" + #{act.id}: {
  "act_id":#{act.id},
  "additional_info":currentTextBoxValue,
  "status":currentStatus
  }
}

I’m pretty sure I can’t chop profile_act_40 into "profile_act_" + #{act.id}, but there’s got to be an easier way to do this.

Once I get this figured out I still am not sure what I would need to incorporate into the profile_acts_controller.rb.

Once again, thank you in advance.


*Revision #2


After working on it a bit more and getting help from my coworker I have this:

:javascript
  $(document).ready(function() {
    jQuery.ajaxSetup({  
      'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}  
    });

    ajaxPost = function (_url, _dataString) {
      $.ajax({
        type: 'POST',
        url: _url,
        data: _dataString,
        success: function() {
          alert("Success!");
        }
        failure: function () {
          alert("Failure!")
        }
      });
    };

    getId = function(object) {
      var _id = $(this).closest(".act").attr("act_id");
      alert("ID got!");
      return _id;
    }

    getInfo = function(object) {
      var _info = $(this).value();
      alert("Info got!");
      return _info;
    }

    getInfoString = function(_id, _info) {
      var _infoString = '"profile_acts":{"profile_act":{"act_id":_id, "additional_info":_info}}';
      alert("Info string got!");
      return _infoString;
    }

    getStatusString = function(_id, _status) {
      var _statusString = '"profile_acts":{"profile_act":{"act_id":_id, "status":_status}}';
      alert("Status string got!")
      return _statusString;
    }

    getUrl = function(_id) {
      var _url = "/profiles/" + _id + "/profile_acts";
      alert("URL got!");
      return _url;
    }

    showAlert = function(msg) {
      alert(msg);
    }

    $('.info_field').change(function() {
      var _id = getId($(this));  
      var _info = getInfo($(this));
      var _dataString = getInfoString(_id, _info);
      var _url = getUrl(_id);

      var message = "hello text";
      showAlert(message);
    });

    $('.status_yes_field').change(function() {
      var _id = getId($(this));  
      var _info = getInfo($(this));
      var _dataString = getStatusString(_id, _info);
      var _url = getUrl(_id);

      var message = "hello yes";
      showAlert(message);
    });

    $('.status_maybe_field').change(function() {
      var _id = getId($(this));  
      var _info = getInfo($(this));
      var _dataString = getStatusString(_id, _info);
      var _url = getUrl(_id);

      var message = "hello maybe";
      showAlert(message);
    });

    $('.status_no_field').change(function() {
      var _id = getId($(this));  
      var _info = getInfo($(this));
      var _dataString = getStatusString(_id, _info);
      var _url = getUrl(_id);

      var message = "hello no";
      showAlert(message);
    });
  });

I tried to have debugging alerts where I could, but absolutely nothing is registering and I am at a complete loss with low gumption. I am not sure where to go forward with this or even side-step and try something new. I can’t help but feel like I am missing something very basic here. Thanks in advance again.

  • 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-25T23:10:19+00:00Added an answer on May 25, 2026 at 11:10 pm

    Welllllll, thanks to only Tejs on this, but this is what I needed.

    $(".description_form input, #certificates_holder ul li input").change(function(){
    
      form = $("#actions form");
    
    $.ajax({data:jQuery.param(form.serializeArray()), dataType:'script', type:'post', url: "/profiles/" + $("#profile").attr("data-profile_id") + "/profile_acts"});
    
    });
    
    
    $(".additional_info_form textarea").change(function(){
    
        form = $("#actions form");
    
    $.ajax({data:jQuery.param(form.serializeArray()), dataType:'script', type:'post', url: "/profiles/" + $("#profile").attr("data-profile_id") + "/profile_acts"});
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have previous experience with MATLAB, but the problem that I face is some
I am writing a simple database with web access. I have previous experience with
I have First/Last/Previous/Next buttons that change the selected child node of a TreeViewItem. Setting
From a previous question I have seen that the CLR has workstation and server
I have code examples from some of my previous work that help me to
In my previous web development experience I have used LAMP setups. I am trying
Migrating from PHP to EJB , I have previous experience of PHP , C++
I don't have any previous experience creating ActiveX-Controls. Information about the topic thats not
Just started to play around with node.js, have some past experience with JavaScript but
I have previous JSP experience but with using Tomcat and Resin and I would

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.