2

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);

                        }
                    }

                });
2
  • It would help if we knew what the server code returns. Also, what line throws the syntax error? Commented Dec 5, 2012 at 17:31
  • i suggest msg.d is throwing error here. there is no 'd' attached to msg. Commented Dec 5, 2012 at 17:32

1 Answer 1

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

You want:

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

You're confusing contains with the jQuery DOM method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.