javascript - Replace is not defined, but why? - Stack Overflow

can somebody tell me what is wrong?JS Code$.ajax({url:"",success:function(data){var test_data


can somebody tell me what is wrong?

JS Code

$.ajax({
    url:"",
    success:function(data){

        var test_data = ''+data+''; // convert object to a string
        $('body').append(typeof(test_data));

        var test_data = replace.test_data(/[0-9]/,'X');
        $('body').append('<hr />'+test_data+' <hr />');

    },
    dataType:'jsonp',
    error:function(){
        alert('error');
    }
});

jsfiddle /

Thanks in advance!
Peter


can somebody tell me what is wrong?

JS Code

$.ajax({
    url:"http://www.google.com/complete/search?qu=chicken",
    success:function(data){

        var test_data = ''+data+''; // convert object to a string
        $('body').append(typeof(test_data));

        var test_data = replace.test_data(/[0-9]/,'X');
        $('body').append('<hr />'+test_data+' <hr />');

    },
    dataType:'jsonp',
    error:function(){
        alert('error');
    }
});

jsfiddle http://www.jsfiddle.net/V9Euk/664/

Thanks in advance!
Peter

Share Improve this question asked Oct 10, 2010 at 16:37 PeterPeter 11.8k31 gold badges101 silver badges154 bronze badges 1
  • get your hand on a good debugger like: getfirebug.com – gblazex Commented Oct 10, 2010 at 16:46
Add a comment  | 

3 Answers 3

Reset to default 11

You got it backwards; it should be

test_data.replace(...);

Also, you don't need var before the second assignment to "test_data"; just the first one.

replace is undefined. It is not an object.

Use replace from the string prototype

"string".replace(//, "");

As you can see:

alert(String.prototype.replace)

Results in

function replace() {
    [native code]
}

You should replace replace.test_data by test_data.replace

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1739444698a4127572.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信