Friday, February 21, 2014

[JQuery][Solved] Uncaught TypeError: Object " has no method 'encodeURIComponent'

Finally found the error is not related to the message mentioned again:



Uncaught TypeError: Object " has no method 'encodeURIComponent' 
So , what cause that?
wrong syntax !


case "or":
case "or1":
    searchquery = prequery+'"'+encodeURIComponent($('#or').val())+'"+OR+"'+encodeURIComponent($('or1').val())+'"';
    $('#search_query').html(searchquery.replace(/%20/g, '+'));
break;
case "remove":
case "remove1":
    searchquery = prequery+'"'+encodeURIComponent($('remove').val())+'"+-"'+encodeURIComponent($('#remove1').val())+'"';
    $('#search_query').html(searchquery.replace(/%20/g, '+'));
break;
case "and":
    searchquery = prequery+'"'+encodeURIComponent($('#and').val())+'"+%2"'+encodeURIComponent($('and1').val())+'"';
    $('#search_query').html(searchquery.replace(/%20/g, '+'));
break;



============= END of the solution of Uncaught TypeError: Object "...==============
Others
Another problem I found in this example:
I have missed the syntax of ID selector .....


So I need the "#" shown in green, highlight with yellow:
case "or":
case "or1":
    searchquery = prequery+'"'+encodeURIComponent($('#or').val())+'"+OR+"'+encodeURIComponent($('#or1').val())+'"';
    $('#search_query').html(searchquery.replace(/%20/g, '+'));
break;
case "remove":
case "remove1":
    searchquery = prequery+'"'+encodeURIComponent($('#remove').val())+'"+-"'+encodeURIComponent($('#remove1').val())+'"';
    $('#search_query').html(searchquery.replace(/%20/g, '+'));
break;
case "and":
    searchquery = prequery+'"'+encodeURIComponent($('#and').val())+'"+%2"'+encodeURIComponent($('#and1').val())+'"';
    $('#search_query').html(searchquery.replace(/%20/g, '+'));
break;


No comments :

Post a Comment