开发者

jquery ajax request is Forbidden in IE. How to fix (any workaround)?

开发者 https://www.devze.com 2022-12-24 13:51 出处:网络
<script type=\"text/javascript\"> $(function () { $(\"select#oblast\").change(function () { var oblast_id = $(\"#oblast > option:selected\").attr(\"value\");
 <script type="text/javascript">
        $(function () {
            $("select#oblast").change(function () {
                var oblast_id = $("#oblast > option:selected").attr("value");
                $("#Rayondiv").hide();
                $.ajax({
                    type: "GET",
                    contentType: "application/json",
                    url: "http://site.com/Regions.aspx/FindGorodByOblastID/",
                    data: 'oblast_id=' + oblast_id,
                    dataType: "json",
                    success: function (data) {                       
                        if (data.length > 0) {

                            var options = '';
                            for (p in data) {
                                var gorod = data[p];
                                options += "<option value='" + gorod.Id + "'>" + gorod.Name + "</option>";
                            }
                  开发者_如何学运维          $("#gorod").removeAttr('disabled').html(options);

                        } else {

                            $("#gorod").attr('disabled', false).html('');
                        }
                    }
                });
            });
        });
</script>


If you're trying to call a URL on a third-party site you will need to look in to JSONP (JSON with Padding) options. These are designed to make it slightly easier to work with third-party services.

See jQuery.ajax and the discussion of the "jsonp" in there for some additional details.


Where is this code running? Unless you're on http://site.com/, that won't work for security reasons.

If that's the case, is there any way you make the request and do whatever server side?

Maybe make the request to some page you set up on your site, and in its code behind do the work:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://example.com");
request.Method = "GET";
request.Headers["Accept-Encoding"] = "gzip,deflate";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String html = new StreamReader(response.GetResponseStream()).ReadToEnd();
response.Close();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号