What is wrong with eval?

  • Thread starter Thread starter KELLY_IRVINE
  • Start date Start date
K

KELLY_IRVINE

Guest
I have a question on EVAL function.

I got following function using EVAL function in C# code in aspx file which was developed by previous web developer with Visual Studio 2010. Here is description of this function

Purpuse: Get column Data-A from table-A through sampleAjax and return the value.

(1) Calling sampleAjax with parameter p1 and p2 at Line 8

(2) The sampleAjax get column 'Data-A' which is 8 length varchar type value from 'table-A'

(3) Set the return value from the sampleAjax to sReturn at Line 15

(4) Return value at Line 22




1 function SampleFunction(p1, p2)
2 {
3
4 var sReturn = "";
5 $.ajax(
6 {
7 type: "POST",
8 url: "SampleASPX.aspx/SampleAjax",
9 data: "{'p1':'" + p1 + "','p2':'" + p2 + "'}",
10 contentType: "application/json; charset=utf-8",
11 async: false,
12 dataType: "json",
13 success: function(data)
14 {
15 sReturn = eval(data.d);
16 },
17 error: function(response)
18 {
19 alert('sampleFunction failed: ' + response.status + ' ' + response.statusText);
20 }
21 });
22 return sReturn;
23 }



This code has been running fine for a long time. Recently we set 20 length value to column 'Data-A' in the 'Table-A'. That's the only changed. No changed in the function and ajax function above. When I run the program, the return value from the function is NULL without error, then I run it with debug mode, it goes fine until calling the EVAL at the line 15 as follows

sReturn = eval(data.d);


I can see the [data.d] contains correct value which is 20 length value which is return from the SampleAjax, but somehow the EVAL function set NULL to sReturn after that. I don't know why the EVAL function reject to set 20 length value. I am not sure what EVAL function for here. Can the function have something like configuration file that can set up if the length is more than 8, set null or something.

Any advice will be gratefully appreciated. Thank you..

Continue reading...
 
Back
Top