سؤال

I have a jquery on button click it runs a function in backend code. my code will return a string which may contain some values. Can I say if my string contains then means success otherwise show error(see my code below), the following code throws a syntax error:

$.ajax({
                    type: "POST",
                    url: "MyPage.aspx/MyFunction",
                    data: "{'totalToPay': '" + totalToPay + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

                    success: function (msg) {
                        if (msg.d.contains('https://')) { // THIS IS WHERE IT THROWS ERROR. AM DOING THIS AS MY STRING MAY CONTAIN http://www.test.com
                            alert("TEST");
                        }
                        else {
                            $("#error").show();
                            msgbox.html(msg.d);

                        }
                    }

                });
هل كانت مفيدة؟

المحلول

msg.d.contains('https://')

You want:

msg.d.indexOf('https://') > -1

You're confusing contains with the jQuery DOM method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top