简体   繁体   中英

Accessing jQuery returned value

I'm trying to access the returned value and add a check of .contains so I can know if I need to reload the page or not. I've been trying to do something like the following:

alert(msg.d);
if(msg.d.contains("deleted"))
    location.reload();

The returned object is a string.

It does show me the alert message, but won't reload the page once it's necessary. Did I do something wrong?

There is no .contians() method, You need to use String.prototype.indexOf()

The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.

Code

if(msg.d.indexOf("deleted") > -1)
    location.reload();

Use JavaScript's hasOwnProperty function, like this:

if(msg.d.hasOwnProperty("deleted") {
    location.reload();
}

You can try something like this:

if( /deleted/.test(msg.d) ) {
    location.reload();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM