原来一直使用hbulider,最近不能打包苹果发布包,只能改用hbuliderx 结果连真机运行都不行了,应该是跨域的问题
下面第主要的代码
function webservice(url, options) {
if (typeof (url) == 'object') { //将url写在options里的情况
options = url;
url = url.url;
}
if (!url) return;
if (options.dataType.toLowerCase() == 'json') { //请求JSON格式的数据时,url后面需要加上“/方法名”
url = url + '/' + options.method;
}
var xmlHttp = getXmlHttp(); //获取XMLHttpRequest对象
xmlHttp.open('POST', url, true); //异步请求数据
xmlHttp.onreadystatechange = function () {
console.info(xmlHttp.readyState);
console.info("respnosetext:"+xmlHttp.response);
if (xmlHttp.readyState == 4) {
try {
console.info("xmlHttp.status:"+ xmlHttp.status);
if (xmlHttp.status == 200 && typeof (options.success) == 'function') {
options.success(xmlHttp.responseXML);
}
else if ((xmlHttp.status== 400 || xmlHttp.status==500) && typeof (options.error) == 'function') {
console.info("" +xmlhttp.status);
options.error(xmlHttp.responseText, xmlHttp.status);
}
else if (xmlHttp.status / 100 == 200 && typeof (options.complete) == 'function') {
options.complete(xmlHttp.responseText, xmlHttp.status);
}
else if (typeof (options.failed) == 'function') {
options.failed(xmlHttp.responseText, xmlHttp.status);
}
}
catch (e) {
alert("XML文档出错" + e.message);
}
}
}
xmlHttp.setRequestHeader('Content-Type', options.contentType); //设置请求头的ContentType
xmlHttp.setRequestHeader('SOAPAction', options.namespace + options.method); //设置SOAPAction
xmlHttp.send(options.data); //发送参数数据
}
‘--------------------------------------------------------------------------------------------------------’
document.getElementById('loadsheet').style.visibility='visible';
var data = '<?xml version="1.0" encoding="utf-8"?>'
- '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
- '<soap:Body>'
- '<Servercheckcode xmlns="http://tempuri.org/">'
- '<Checkcode>' + checkcodeValue+ '</Checkcode>'
- '</Servercheckcode>'
- '<Servercheckcode xmlns="http://tempuri.org/">'
- '</soap:Body>'
- '<soap:Body>'
-
'</soap:Envelope>';
var options = {
namespace: 'http://tempuri.org/',
method: 'Servercheckcode',
contentType: 'text/xml; charset=utf-8',
dataType: 'xml',
data: data,
success: function (msg) {
if(msg){
console.info("XMLdoc:");
var messageNode = msg.getElementsByTagName("ServercheckcodeResult");
if(messageNode.length>0){
var textNode = messageNode[0].firstChild;
var responsemessage=textNode.nodeValue;
var list=responsemessage.split("/");
console.info("返回值:" + list[0]);
if (list.length>0){
if (list[0]=="0"){
localStorage.setItem("ZZXTserverip",serveripvalue);
localStorage.setItem("ZZXTcheckcode",checkcodeValue);
mui.openWindow({
url:'../models/login/login.html',
id:'login'
});
}else{
alert("输入的系统识别码不正确!");
localStorage.clear();
}} } document.getElementById('loadsheet').style.visibility='hidden'; }else{ alert("出错了"); } }, error:function(msg,state){ alert(msg); } }; conntrue=1; webservice(webserveradd, options);
});
服务器端是vb.net 写的webserver
网上也查很久,没有成功,请教大侠帮忙。
0 个回复