April 12, 2012

Escape all special characters in a string that is sent by jquery ajax

Question by developer747

I am trying to send text in key value pairs while doing a contentType: "application/json; charset=utf-8", ajax post to a web service. The problem I am facing is that if one of the parameters (that accepts text from the user) has quotes (“) it breaks the code [Eror message: Invalid object passed in ] . So far I have tried these without any success

var text = $("#txtBody").val(); 
var output1 = JSON.stringify(text); 
var output2 = text.replace(/[-[]{}()*+?.,\^$|#s]/g, "\$&"); 

Any ideas on how to escape the special characters for the jquery ajax post?

Answer by Trevor

Answer by Starx

There is already a function escape(var) which helps you escape the values. It should be enough for the purpose you are talking about

var output2 = escape(text);
April 7, 2012

Hide "www" text in URL bar (firefox)

Question by Futur Fusionneur

I was wondering if it is possible to hide the “www” text in the URL bar (only in Firefox) using CSS in Stylish addon or/and Java in Greasemonkey.

I want this to make Firefox even more compact.

This is some CSS code that i found for URL bar in firefox that will modify the text size using Stylish. Hope it can help.

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

.searchbar-textbox {
 font-size: 11px !important;


I don’t want to remove the “www”, I just want to hide it from the url bar.

Answer by Starx

You have to use .htaccess for this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Replace example.com with your domain name.

August 4, 2010

Text to HTML in PHP

Question by user409257

nl2br(); can do for EOL but what about white spaces and/or tabs at the beginning(or not) of line? Is there any function to do this at once? I need well formatted html output of text file.

Answer by Starx

well may be <pre>....</pre> can do it

also see






Please fill the form - I will response as fast as I can!