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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:44:54+00:00 2026-05-18T21:44:54+00:00

In a previous question I asked how to implement a client side bad word

  • 0

In a previous question I asked how to implement a client side bad word filter.

The problem I have is that I don’t want to send the masive string to the page, but rather call it from an external file.

here’s the code so far

    var filter = ['ass']; // this is a literal JSON result
    String.prototype.repeat = function (num) {
        return new Array(num + 1).join(this);
    }

    $('body').html(function (i, txt) {
        for (var i = 0; i < filter.length; i++) {

            // Create a regular expression and make it global
            var pattern = new RegExp('\\b' + filter[i] + '\\b', 'g');

            txt = txt.replace(pattern, "****");
        }

        return txt;
    });

But I’d like to change it to soemthing like

    var filter = '/generic/profanity/'; // the "profanity" page generates the exact 
                                        // same JSON result as above only in a cached
                                        // external page (it's actually generated by
                                        // an ASP.NET MVC Controller (ContentResult)
    String.prototype.repeat = function (num) {
        return new Array(num + 1).join(this);
    }

    $('body').html(function (i, txt) {
        for (var i = 0; i < filter.length; i++) {

            // Create a regular expression and make it global
            var pattern = new RegExp('\\b' + filter[i] + '\\b', 'g');

            txt = txt.replace(pattern, "****");
        }

        return txt;
    });

but unfortunately with this, it’s using '/generic/profanity' as a literal string for the regex rather than a reference path.

This is probably something really stupid, but how would I fix this?

Edit:

after @GSP’s answer I’m trying this approach, and though it feels closer, it’s still not working.

If I go into firebug and look at the “filter” variable in the DOM, it is represented as ['asdf']

    var filter = '';

    String.prototype.repeat = function (num) {
        return new Array(num + 1).join(this);
    }

    $('.page').html(function (i, txt) {

        $.getJSON('/generic/profanity', function (data) {

            // data is the contents of the 
            filter = data;

        });

        for (var i = 0; i < filter.length; i++) {

            // Create a regular expression and make it global
            var pattern = new RegExp('\\b' + filter[i] + '\\b', 'g');

            txt = txt.replace(pattern, "****");
        }

        return txt;
    });
  • 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-18T21:44:54+00:00Added an answer on May 18, 2026 at 9:44 pm

    Because the JQuery will always be run from the browser context you will always be downloading the file anyway so this isn’t going to work the way you think it is.

    But, if you want to use this method you’ll want to use one of the JQuery methods like $.get, or $.getJSON to get the file from your server before you parse it:

    var filter = '';
    $.getJSON('/generic/profanity', function(data) {
    
      // data is the contents of the 
      filter = data;
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation question from a previous question I have asked I now
From a previous question I have seen that the CLR has workstation and server
this question is an extension to a previous question i asked (and was answered).
I'm quoting myself on a previous question I asked to further explain: I'm trying
In a previous question, I asked about various ORM libraries. It turns out Kohana
Continuing from my previous question , is there a comprehensive document that lists all
We determined in a previous question that many features of HTML SELECTs are not
I have been asked by a client to return a 410 Status code for
So in a previous question I asked about implementing a generic interface with a
This question is directly related to my previous question ASP.NET AJAX Is it possible

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.