Jquery gives a Syntax error, unrecognized expression on calling a url including “(”

i am facing an error in Jquery Load function. I am using jquery to find a string in MySQL database table. here is a sample of my code.


here, i am using "code" as input. when i use "(" in code like:

code = "DQ118 (dq10)";

browser gives me an error like:

Uncaught Syntax error, unrecognized expression:  (


It works pretty fine, look here. Just maybe try to encode your URI, by using encodeURIComponent

code = "DQ118 (dq10)";

and use var before you declare your variable. For example

var code = "DQ118 (dq10)";
var nUrl='count.php?coun='+encodeURIComponent(code);

so you avoid declaring your variable globally

First of all you must declare the variables ( var code = 'blah'; )

also, "escape" the string:

var code = escape("DQ118 (dq10)");
var nUrl = 'count.php?coun='+code;

I've tried it and i don't get that error. In any case you should use encodeURIComponent i think on the code variable

code = encodeURIComponent("DQ118 (dq10)");

follow this previous question on this site Escaping HTML strings with jQuery

it is much clear to understand and help to solve further problems like this..

it works somewhat like this:

html.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");

Need Your Help

Funny Thread Behaviour in Scala

java multithreading scala

I'm making some experiments to try and understand Threads in practice. Please look at the following snippet: It's a main function that spawns a thread listening on port 2020. This thread, in turn,

Why are the call stacks different when a test crashes at the exact same statement?

java reflection junit

For a research project, I'm trying to figure out if unit tests (written in JUnit) behave differently when executed in different contexts. For this I do two things: first, I run the entire test suit...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.