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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:53:01+00:00 2026-05-24T03:53:01+00:00

I have an ajax form that I would like to submit, and the response

  • 0

I have an ajax form that I would like to submit, and the response contains two divs, one containing html content and the other containing dynamic javascript in a script tag.

I’m submitting the form and receiving the response ok, but I can’t seem to get the javascript to evaluate. I’ve put an alert inside but it never fires. This is the code I am using to submit the form:

$("#categoryFormSubmit").live("click", function(event){
        event.preventDefault();
        var action = this.form.action + '?_eventName=' + this.name + 'Ajax';
        var params = $(this.form).serialize();
        var xhr = $.post(action, params, function(response) {
            var responseDom = $(response);
            var contentData = $('#content', responseDom).html();
            var javascriptData = $('#javascript', responseDom).html();
            $('#content').html(contentData);
            $('#javascript').html(javascriptData);
        }, 'html');
    }); 

In the response I am trying to convert the response data to a DOM object and parse out the content and the javascript, and insert them into the existing dom. The content replacement works fine, but nothing seems to be working with the javascript. I can’t get it to evaluate. How should I be doing this? I imagine I shouldn’t be trying to insert it into the DOM like I am.

  • 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-24T03:53:04+00:00Added an answer on May 24, 2026 at 3:53 am

    There is no need to manually parse the response and separately add the HTML and JS to your page. jQuery will detect scripts inside of markup you attempt to add to the DOM and will handle the proper addition and execution of them.

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

Sidebar

Related Questions

I have a dynamically generated form that I would like to submit using Ajax.
I have a basic form that I would like to submit using ajax, without
I have a standard html form that uses a background image. I would like
I have a jQuery ajax function and would like to submit an entire form
I have a popup div containing a form that when closed i would like
I have an Ajax form that updates a div when submitted with a submit
I have an ajax form I would like to prevent from preforming an action
I have two pieces of javascript that I would like to work together. I
What I have: I have a form that I submit via AJAX. <%= form_for([@map,
I have an Ajax contact form that links to a jquery file but for

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.