I am getting a strange error in my javascript code.
Here is the code sample
function FetchData()
{
var selValue=$("select[id$=ddlComponents]").val()
var param=$.param({ID:selValue});
var method="proxy.aspx/GetComponentsValuesAgainstOilValue";
$.ajax({
type: "POST",
url: method,
data: param,
contentType: "application/json",
dataType: "json",
success: function(response) {
if (response.replace(/"/g, '') == '{d:[]}')
{
response = eval('(' + response + ')').d;
}
},
error: function(xhr,error,status)
{
alert(error);
}
});
}
It gives me an error at following line of code
if (response.replace(/"/g, '') == '{d:[]}')
{
response = eval('(' + response + ')').d;
}
object does not support property or function 'replace'. But replace function is working with string variables otherwise.
My JQuery ver is 1.6.4
Please help.
Thanks vivek
response
is already an object. You don't need to do any JSON parsing on your own.
The type of response is clearly not an object of the type string. Try to parse it as a string or look what's inside the object that is currently being returned and use that in a proper way. In other words...see what your method "GetComponentsValuesAgainstOilValue" is returning to the client. That's probably what is in your response object at the moment (in JSON).
The data parameter taken by success callback is formatted according to the dataType parameter. In your case - "json", so your data is an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With