js/jquery 跨站提交

来源:互联网 发布:身份证伪造软件app 编辑:程序博客网 时间:2024/06/04 01:06

方法一:iframe提交

var _login_lock = 0;function LoginSubmit() {    var a, actionURL = "http://www.aaa.aaa", loginName = document.getElementById("login_username"), loginPaswd = document.getElementById("login_password");    if (loginName.value == '' || loginName.value == "用户名/E-mail") {        alert('请输入用户名/E-mail'); loginName.focus(); return false    }    else if (loginPaswd.value == '') {        alert('请输入登陆密码'); loginPaswd.focus(); return false    } else {        a = { "username": loginName.value, "password": loginPaswd.value };        if (_login_lock == 0) {            _login_lock = 1;            createFormAndSubmit(a, actionURL, "loginwin", "POST");        }    }}if (top != self) top.location = self.location;function getNewSubmitGetForm(a) { var b = document.createElement("FORM"); document.body.appendChild(b); b.method = a; return b }function getNewSubmitForm() { var a = document.createElement("FORM"); document.body.appendChild(a); a.method = "POST"; return a }function createFormAndSubmit(a, b, c, d) { var e = (d == undefined && d == null) ? getNewSubmitForm() : getNewSubmitGetForm(d); for (var f in a) { if (a[f] != "") createNewFormElement(e, f, a[f]) } e.action = b; if (c != undefined && c != null) { e.target = c } e.submit(); return e }function createNewFormElement(a, b, c) { var d = document.createElement("INPUT"); d.type = "hidden"; d.name = b; a.appendChild(d); d.value = c; return d }
<iframe name="loginwin" id="loginwin" style=" display:none;" ></iframe>
页面上添加上面html代码

方法二:jquery的jsonp提交方式
$.ajax({        type: "get",        async: false,        url: "http://aaa.aaa.com?aa=aa",        dataType: "jsonp",        jsonp: "callbackparam",        jsonpCallback: "success_jsonpCallback",        success: function (json) {            var d = eval(json);                    },        error: function (e) {            alert(e);        }    });

服务器返回数据格式必须是success_jsonpCallback(" + result + "); 对应jsonpcallback里面的参数

0 0
原创粉丝点击