-2

可能重复:
规避同源策略的方法

我必须在 HTML 页面中使用 AJAX 调用从另一个 IP 调用 REST Web 服务。但是,AJAX 调用不支持跨域请求。

我正在使用 JSON-P,但在我的应用程序中没有得到结果。

这是我发出 JSON-P 请求的 jQuery 代码:

var makePUTRequest = function () {
            $.ajax({
                type: "POST",
                url: "http:// 
                contentType: "application/jsonp",
                data: '{"username1":"getStates", "password1":"EXPLORE"}',            
                dataType: "jsonp",
                success: function (response) {

                    if (response == ("success").toLocaleLowerCase()) {

                        alert("Loging Successfully!!..");
                        window.location = "patient_list.html";
                    }
                    else {
                        alert("Please Loging Again!!..");
                    }
                },
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("My-Key", 'MyKey123456789');
                },
                error: function (error) {

                    alert("ERROR:", error);

                },
                complete: function () {
                    alert("complete");
                }
            });

        };  
4

1 回答 1

-2
     var makePUTRequest = function () {
                $.ajax({
                    type: "POST",
                    url: "http:// 
                    contentType: "application/jsonp",
                    data: '{"username1":"getStates", "password1":"EXPLORE"}',            
                    dataType: "jsonp",
                    success: function (response) {

                        if (response == ("success").toLocaleLowerCase()) {

                            alert("Loging Successfully!!..");
                            window.location = "patient_list.html";
                        }
                        else {
                            alert("Please Loging Again!!..");
                        }
                    },
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("My-Key", 'MyKey123456789');
                    },
                    error: function (error) {

                        alert("ERROR:", error);

                    },
                    complete: function () {
                        alert("complete");
                    }
                });

            };  

        </script>

js file 1.7.1.js download from google
于 2012-12-18T09:41:09.560 回答