Reputation: 2758
So I have the following function on a page that is supposed to be calling an asp.net webservice and it appears to be doing so but nothing ever happens on the page. Below is the function below that is the webservice
$("#BlogSelectList li a").click(function () {
var str = ($(this).attr("href")).slice(1, 36)
$.ajax({
contentType: "application/json; charset=utf-8",
url: '../ws/WebServices.asmx/SetActiveBlog',
data: '{ActiveBlogID: "' + str + '"}',
dataType: 'json',
type: "post",
success: function (j) {
if (j.d == 1) {
window.location('http://www.msn.com');
}
else {
window.location('http://www.msn2.com');
}
alert('heyhi')
}, error: function (j) {
alert(':(')
}
});
});
Here is the webservice, I know it is executing because it is running a stored procedure which is making a log entry successfully with "ssss" but the page literally does nothing when the anchor is clicked it doesnt redirect the page, it doesn't do any alert, nothing.
[WebMethod(Description = "Sets the ActiveBlog.")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool SetActiveBlog(string ActiveBlogID)
{
DbaseExecSpWithReturnValue Sproc = new DbaseExecSpWithReturnValue();
Sproc.SetSp("sp_CheckUsernameAvailable");
Sproc.AddParam(1);
Sproc.AddParam("Username", SqlDbType.Char, "ssss", 20);
int RetVal = Sproc.Execute();
Sproc.Close();
return true;
}
Upvotes: 1
Views: 373
Reputation: 584
$("#BlogSelectList li a").click(function () {
var str = $(this).attr("href").slice(1, 36);
$.ajax({
contentType: "application/json; charset=utf-8",
url: '../ws/WebServices.asmx/SetActiveBlog',
data: '{ActiveBlogID: "' + str + '"}',
dataType: 'json',
type: "post",
success: function (j) {
if (j.d == 1) {
window.location = 'http://www.msn.com';
}
else {
window.location = 'http://www.msn2.com';
}
alert('heyhi');
}, error: function (j) {
alert(':(');
}
});
});
Upvotes: 1
Reputation: 81684
window.location
is not a function you call, it's a property you set:
if (j.d == 1) {
window.location = 'http://www.msn.com';
}
etc.
Upvotes: 3
Reputation: 41236
I believe that is because you are calling window.location()
instead of setting window.location.href = 'someUrl'
.
Upvotes: 2