[英]login into the site with my javascript
i'm trying to login into the site with the following javascript. 我正在尝试使用以下javascript登录该网站。 But, i'm loading only the complete page.
但是,我只加载整个页面。 I'm developing windows 8 app
我正在开发Windows 8应用
(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";
}
}
};}
I want to dsiplay in xhrdiv.innerHTML
as "LOGIN SUCCESS" or "LOGIN ERROR" 我想在xhrdiv.innerHTML中
xhrdiv.innerHTML
为“登录成功”或“登录错误”
EDIT: 编辑:
I tried the following code: 我尝试了以下代码:
iframe = document.getElementById("ifra_op"); iframe.setAttribute("src", "http://www.160by2.com/index"); document.getElementById("op").appendChild(iframe); iframe.contentWindow.document.getElementById("MobileNoLogin") = "<mobno>"; iframe.contentWindow.document.getElementById("LoginPassword") = "<pass>; iframe.contentWindow.document.getElementsByName("LoginForm").click();
But, there is an error. 但是,有一个错误。 It says "Javascript run time error:math is undefined"
它显示“ Javascript运行时错误:数学未定义”
"math" comes from the website. “数学”来自网站。 I don't know how to handle this.
我不知道该如何处理。 Also, the permission is denied.
同样,该权限被拒绝。 Why is that so?
为什么会这样?
You need to make sure you have a service (something like a web service) in the remote server to process the request. 您需要确保在远程服务器中有一个服务(类似于Web服务)来处理请求。
In here what you can do is. 在这里您可以做的是。
Use jquery , makes life easier. 使用jquery,使生活更轻松。
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.