0

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.

nUrl='count.php?coun='+(code);
$('#memory2').load(nUrl);

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:  (
Shahrukh
  • 1,486
  • 5
  • 16
  • 20

4 Answers4

1

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;
John
  • 459
  • 2
  • 6
0

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)");
nUrl='count.php?coun='+code;
$('#example').load(nUrl);
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
0

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

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

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

genesis
  • 50,477
  • 20
  • 96
  • 125
0

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;");
Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75