使用JSONP调用外部网站的WebMethod? [英] Call external site webmethod using jsonp?

查看:270
本文介绍了使用JSONP调用外部网站的WebMethod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用外部网站的WebMethod,并张贴了一些数据。我尝试了很多不同的方式,仍然无法获得被调用的方法。

I'm trying to call external site webmethod, and post some data. I tried a lot of different ways and still cannot get the method to be called.

下面是我的js code:

Here is my js code:

$.ajax({
            url: "http://sitename.com/methods.aspx/mywebmethod",
            data: "{'id':'" + 4 + "'}",
            dataType: "jsonp",
            type: "GET",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                alert(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });

下面是我的webmethod code:

Here is my webmethod code:

[WebMethod()]
        public static bool mywebmethod(int id)
        {
if(id != 0){
            return true;}
else{return false;}
        }

和我总是得到相同的答复。

and I always get the same response

Error: jQuery{code} was not called

我缺少什么?

推荐答案

JSONP不是魔术。

JSONP is not magic.

您只能使用JSONP从返回 JSONP脚本一个URL读取数据。

ASP.Net的WebMethods不支持JSONP。

You can only use JSONP to read data from a URL that returns JSONP script.
ASP.Net WebMethods do not support JSONP.

这篇关于使用JSONP调用外部网站的WebMethod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆