I am trying to use the following code snippet:
console.log(config.url);
if (config.method === 'GET' && config.url.contains("/Retrieve")) {
It outputs:
/Content/app/home/partials/menu.html app.js:255
TypeError: Object /Content/app/home/partials/menu.html has no method 'contains'
at request (http://127.0.0.1:81/Content/app/app.js:256:59)
However this is giving me and error with the word ".contains". Anyone have any idea why I am getting this message?
has no method 'contains'
Does anyone have any idea why I might be getting this message?
I am trying to use the following code snippet:
console.log(config.url);
if (config.method === 'GET' && config.url.contains("/Retrieve")) {
It outputs:
/Content/app/home/partials/menu.html app.js:255
TypeError: Object /Content/app/home/partials/menu.html has no method 'contains'
at request (http://127.0.0.1:81/Content/app/app.js:256:59)
However this is giving me and error with the word ".contains". Anyone have any idea why I am getting this message?
has no method 'contains'
Does anyone have any idea why I might be getting this message?
Share Improve this question asked Feb 13, 2014 at 11:57 Samantha J T StarSamantha J T Star 33k89 gold badges257 silver badges441 bronze badges 03 Answers
Reset to default 8Because in JavaScript, strings don't have a contains
method. You can use indexOf
:
if (config.method === 'GET' && config.url.indexOf("/Retrieve") !== -1) {
Note that that's case-sensitive. To do it without worrying about capitalization, you can either use toLowerCase()
:
if (config.method === 'GET' && config.url.toLowerCase().indexOf("/retrieve") !== -1) {
...or a regular expression with the i
flag (case-Insensitive):
if (config.method === 'GET' && config.url.match(/\/Retrieve/i)) {
The problem is that contains is a jQuery function so you can apply it only on jQuery objects.
If you want to use pure javascript you have to use indexOf function
contains() is not a native JavaScript method; it's used by JS libraries such as jQuery though.
If you're just using pure JavaScript then you could use a method such as indexOf().