Object does not support property or replace method

I get a strange error in my javascript code.

Here is a sample code

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 on the next line of code

if (response.replace(/"/g, '') == '{d:[]}') 
    {
         response = eval('(' + response + ')').d;
    }
An object

does not support the property or function "replace". But instead, the replace function works with string variables.

My jQuery ver 1.6.4

Please, help.

Thanks Vivek

+5
source share
4 answers

responseis already an object. You do not need to parse JSON yourself.

+5
source

. , , , . ... , "GetComponentsValuesAgainstOilValue" . , , ( JSON).

+2

The data parameter received with the callback successfully is formatted according to the dataType parameter. In your case, it is "json", so your data is an object.

+1
source

Some versions of jQuery do not support this method. U need to get the following jquery versions

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
0
source

All Articles