logon

我们这里使用了iframe嵌套form表单POST提交,很简单,却能满足get|post等任何复杂情况的要求;缺点是没有返回值。

针对需要的地方加上一个iframe嵌套并塞入隐藏form表单,然后获取登录表单的值赋予到隐藏form表单提交即可完成跨域POST|get提交。

function smal_send(){
    var user = $("#user_name").val();
    var pass = $("#password").val();
    var form =$("<form action=\'http://www.demo.com/login.php\' method=\'post\'>" +
            "<input type=\'hidden\' name=\'user_name\' value=\'\'/> " +
            "<input type=\'hidden\' name=\'password\' value=\'\'/> " +
            "</form> ");
    $( "#SMAL" ).remove();//清空节点
    $( "body").append("<iframe id=\'SMAL\' name=\'SMAL\' style=\'display: none\'></iframe>");//载入iframe
    (function(){
        $( "#SMAL" ).contents().find(\'body\').html(form);//将form表单塞入iframe;
        $( "#SMAL" ).contents().find("form input[name=\'user_name\']").val(user);
        $( "#SMAL" ).contents().find("form input[name=\'password\']").val(pass);
        $( "#SMAL" ).contents().find(\'form\').submit();//提交[ps,这里是提交到demo.com,跨域]
    }());
    setTimeout(function(){//如果需要可以跳转到demo.com
        window.location.href="http://www.demo.com/index.php";
    },100)
}
 

javascript是要逆天的。嗯嗯,我觉的是。

 
参考:
 1:http://huangqiqing123.iteye.com/blog/1754108
 
 2:这里介绍了基本的跨域提交方式 http://blog.csdn.net/china_skag/article/details/7410918
 
 3:群友讨论。


4:发散知识点:http://www.cnblogs.com/yjmyzz/archive/2011/04/26/2029699.html

分类:

技术点:

相关文章:

  • 2021-11-15
  • 2021-10-30
  • 2021-11-29
  • 2021-10-19
  • 2022-12-23
  • 2021-11-04
猜你喜欢
  • 2022-12-23
  • 2021-11-19
  • 2021-11-19
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案