Error: Object doesn't support property or method 'indexOf'
I have an ajax call to JsonAction
$.ajax({
url: "/Cancel/",
context: document.body,
success: function (result) {
if (result.indexOf("Authorize") != -1) //indexOf not supported?
window.开发者_StackOverflow中文版location.replace("/Account/LogOn");
//...
};
Why is that happening?
Also i was trying to go like that:
var responce = result;
if (responce.indexOf("Authorize") != -1)
and
var responce = $(result);
if (responce.text().indexOf("Authorize") != -1)
But all the same. Ned help how to make .indexOf working.
The server response is likely being interpreted as JSON, and being converted into a data object automatically by jQuery. In that case it likely won't have an indexOf
member, and it certainly won't be a function.
Try forcing jQuery to leave the response as text by setting the dataType
attribute of your settings object to "text":
$.ajax({
url: "/Cancel/",
dataType: "text",
...
Hi try using this way
$.ajax({
url: "/Cancel/",
context: document.body,
success: function (result) {
var str=String(result);
if (str.indexOf("Authorize") != -1) //indexOf not supported?
window.location.replace("/Account/LogOn");
//...
//...
};
精彩评论