微信小程序如何调用webservice(pb创建的)数据?

  1. 地址rul = "http://anweirj.top/webser/n_webser.asmx?wsdl";(里面是一句话:“xxx + 小程序”)
  2. 如何能在微信小程序里读出来,提供代码片段。


var wsdlurl='http://anweirj.top/webser/n_webser.asmx?wsdl';//wsdl地址

var datacopy ='<?xml version="1.0" encoding="utf-8"?>';

datacopy +='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';

datacopy +='xmlns:xsd="http://www.w3.org/2001/XMLSchema" ';

datacopy +='xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ';

datacopy +='<soap:Body> <nf_str xmlns="http://tempurl.org"> ';

datacopy +='<ls_str>'+此处填写你要发送的值+'</ls_str> </nf_str> </soap:Body> </soap:Envelope>';

wx.request({ url: wsdlurl,

                    data: datacopy,

                    method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT 

                    header: { 'content-type': 'text/xml;',

                   'SOAPAction': 'http://tempurl.org/nf_str',

                    },

                   // 设置请求的 header

                   success: function (res) {

                    // success

                     var resData = res.data;

                     console.log("success: "+resData);

                  },

                 fail: function (res) {

                      console.log("fail: " + res.data)

                  }

})

 

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><nf_strResponse xmlns="http://tempurl.org"><nf_strResult>string小程序</nf_strResult></nf_strResponse></soap:Body></soap:Envelope>

 'content-type': 'text/xml;',
修改成
'content-type':'text/xml; charset=utf-8'

接下来,小程序如何写代码才能取到这条数据,能够赋值给页面的,即:‘xxxx小程序’,刚学小程序编程不要见笑。

  var resData = res.data;

这个变量resData

用字符串截取就可以得到结果