0

我需要调用这个类中定义的 webmethod

<%@ WebService Language="C#" Class="emt7anReyady.myService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Linq;
using System.Web.Security;

namespace emt7anReyady
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class myService : System.Web.Services.WebService
    {
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public void test()
        {
            Context.Response.Redirect("http://www.google.com");
        }
    }
}

我打了一个像这样的 Ajax 调用

function getData() {
                 $.ajax({
                     type: "POST",
                     url: "myService.asmx/test",
                     data: "{}",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function () {
                         alert("succesed")
                     },
                     failure: function () {
                         alert("faild")
                     }
                 });
             }


呼叫失败的问题,在 chrome 控制台中我得到了这个! 错误图像

4

2 回答 2

1

由于使用 of ,您会收到 ThreadAbort 响应Response.Redirect

目前尚不清楚您要使用此代码实现什么 - 如果您想要代理其他站点,您需要阅读和转发响应......

于 2013-07-07T00:26:22.057 回答
0

这是因为您在 WebMethod 中使用了 Response.Redirect。如果您真的想重定向到其他页面,请从成功块中进行。

.
.

success: function () {
                     window.open('http://www.google.com');
                 },
.
.

你也可以使用 document.location 而不是 window.open

于 2013-07-07T06:05:12.603 回答