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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:17:01+00:00 2026-06-05T17:17:01+00:00

I am using Ajax to post the comments of the website. No the user

  • 0

I am using Ajax to post the comments of the website.

No the user can also write some scripts inside a textbox.

The problem is I want to HTML encode it (REMOVE html tags,scripts ETC).

Means remove the html elements.

As far as now i make an unsuccessful try as:

 var textData = $("'" +  $('#textBox').val() + "'").text();

But this is a ridiculous attempt by me. Though it sometimes work but it MAY fail with special symbols etc.

Any help is this regard is deeply appreciated.

Thank You.

EDIT:

Whenever the user post the comment i send the comment to server and at the server side encode it and save it to DB and also on client side update my HTML. I dont want to get the encoded message back from the server

  • 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-05T17:17:03+00:00Added an answer on June 5, 2026 at 5:17 pm

    As everyone else said, please don’t do this. Solve it on the server.

    However, the shortest way to just HTML encode whatever was send (that is, actually print out <b>x</b> is this:

    var yourText = $('#textbox').val(); // or whatever
    var yourTextHTML = $('<span></span>').text(yourText).html();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a form validation using ajax post method. But i got the
How to pass multiple checkboxes using jQuery ajax post this is the ajax function
When a form with a textarea using CkEditor is submitted using ajax the post
When applying the MVP pattern to ASP.NET applications, where does using AJAX to post
I'm having trouble using jQuery.ajax() to post a gist to Github. The gist is
I'm submitting a form using an ajax request (POST method), and checking the HTTP
Im submitting Data to a php file via AJAX using POST. It worked fine
I am using jQuery to do an AJAX POST, but get a CSRF error.
I'm trying to POST a http request using ajax, but getting a response from
I have a problem with loading facebook comments. Well, I'm using the Qawker theme.

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.