使用我的javascript登录到站点
我正在尝试使用以下javascript登录该站点。但是,我只加载整个页面。我正在开发Windows8应用程序使用我的javascript登录到站点,javascript,html,windows-store-apps,Javascript,Html,Windows Store Apps,我正在尝试使用以下javascript登录该站点。但是,我只加载整个页面。我正在开发Windows8应用程序 (function () { "use strict"; WinJS.UI.Pages.define("/pages/home/home.html", { // This function is called whenever a user navigates to this page. It // populates the page elements with th
(function () {
"use strict";
WinJS.UI.Pages.define("/pages/home/home.html", {
// This function is called whenever a user navigates to this page. It
// populates the page elements with the app's data.
ready: function (element, options) {
// TODO: Initialize the page here.
document.getElementById("bt_login").addEventListener("click", login, false);
}
});
})();
function login() {
var xhrDiv = document.getElementById("xhrReport");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = dataLoaded;
xhr.open("POST", "http://www.160by2.com", true, <username>, <password>);
xhr.send();
function dataLoaded() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// OK
xhrDiv.innerHTML = window.toStaticHTML("response:" + xhr.responseText);
} else {
// not OK
xhrDiv.innerText = "failure";
}
}
};}
(函数(){
“严格使用”;
定义(“/Pages/home/home.html”{
//每当用户导航到此页面时,都会调用此函数。它
//用应用程序的数据填充页面元素。
就绪:功能(元素、选项){
//TODO:在此处初始化页面。
document.getElementById(“bt_登录”).addEventListener(“单击”,登录,错误);
}
});
})();
函数登录(){
var xhrDiv=document.getElementById(“xhrReport”);
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=dataLoaded;
xhr.open(“POST”http://www.160by2.com“,没错,);
xhr.send();
函数dataLoaded(){
if(xhr.readyState==4){
如果(xhr.status==200){
//嗯
xhrDiv.innerHTML=window.toStaticHTML(“响应:+xhr.responseText”);
}否则{
//不好
xhrDiv.innerText=“失败”;
}
}
};}
我想在xhrdiv.innerHTML
中显示为“登录成功”或“登录错误”
编辑:
我尝试了以下代码:
iframe=document.getElementById(“ifra_op”);
setAttribute(“src”http://www.160by2.com/index");
document.getElementById(“op”).appendChild(iframe);
iframe.contentWindow.document.getElementById(“MobileNoLogin”)=“”;
iframe.contentWindow.document.getElementById(“LoginPassword”)=”;
iframe.contentWindow.document.getElementsByName(“LoginForm”)。单击();
但是,有一个错误。它说“Javascript运行时错误:数学未定义”
“math”来自网站。我不知道如何处理此问题。此外,权限被拒绝。为什么会这样?您需要确保远程服务器中有一个服务(类似于web服务)来处理请求 在这里你能做的就是
var iframe = $("#ifra_op");
$(iframe).attr("src", "http://www.160by2.com/index");
$(iframe).attr("onload","submitForm();");
function submitForm(){
$(iframe.contentWindow.document).find("#MobileNoLogin").val("9999");
$(iframe.contentWindow.document).find("#LoginPassword").val("pass");
$('#button').click();
}
到底是什么不起作用?嘿。它说访问被拒绝了。你能给我更多的细节,比如截图什么的吗