如何在javascript中将元素值(sid和stmp值)作为键值对调用? [英] How to call element values (sid and stmp values) as key value pairs in javascript?

查看:112
本文介绍了如何在javascript中将元素值(sid和stmp值)作为键值对调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html页面.

我正在对链接进行ajax调用,并且获取了其中包含sId和sTmp值的html数据.我需要在html页面中将sId和sTmp的所有值作为键值对.

(大约有106个sId和sTmp值)

如何获取sId和sTmp的所有值作为键值对?

包含sId和sTmp值的html数据代码:-

I have an html page.

I am making an ajax call to a link and i get the html data which contains sId and sTmp values in it. I need to get all the values of sId and sTmp as key value pairs in my html page.

(There are about 106 sId''s and sTmp values)

How to get all the values of sId and sTmp as key value pairs ?

Code of html data which contains sId and sTmp values:-

sId = "1407900387";

    if ((3 == 13) && "")

{
  var sLinkLocation = sAddJavascriptEscapes('');

  sUrl = "OpenInformationItemLocation(\"" + sLinkLocation + "\", );";

}

else

  sUrl = "OpenHeaderLinkFromTable(\"http://172.220.1.4/QPR2014-1/Portal/QPR.Isapi.dll?PGPLUGIN&*24&SES=mWh8OHy43bW3LC5kC9yM-A&FMT=p&SKIN=portal&LAN=en%2c1&MODELID=1470448858&OBJECTID=1407900387\",\"http://172.220.1.4/QPR2014-1/Portal/QPR.Isapi.dll?PGPLUGIN&*24&SES=mWh8OHy43bW3LC5kC9yM-A&FMT=p&SKIN=portal&LAN=en%2c1&MODELID=1470448858&OBJECTID=1407900387\",\"" + sId + "\");";

window._sDefaultLink = window._sDefaultLink || sUrl;

RC("<table border='0' cellpadding='0' cellspacing='0'><tr><td><a id=\"a" + sId + "\" href='java<!-- no -->script:" + sUrl + "' title='" + sTmp + "'><img src='http://172.220.1.4/QPR2014-1/qprsoftware/pg/images/icn_subprocess.gif' title='" + sTmp2 + "'> " + sTmp + "<\/a>" + sTools + "</td></tr></table>", sTmp);

sTmp = "";

if (sTmp != "")

  sTmp = "<table border='0' cellspacing='0' cellpadding='0'>" + sDecodeURI(sTmp) + "</table>";

RC(sTmp, "");



html页面代码:-



Code of html page:-

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="jquery.js"></script>
<script type="text/javascript">

function dataRet (d){
console.log(d);
}
function ajaxreq(){
debugger
 $.ajax({

url: *some link*
      error: function(jqxhr) {
          alert(jqxhr.responseText); // @text = response error, it is will be errors: 324, 500, 404 or anythings else
          },
      dataType:'html',
      success: function(data) {
           alert(data);
           console.log(data);
           var decoding = sDecodeURI(data);
           console.log(decoding);
      },

      type: 'post'
   })

function sDecodeURI(vsStr) 
{
debugger
  try {
    if (typeof(vsStr) !== "string")
      return vsStr;

    var slSplit = vsStr.split('%u');
    if (slSplit.length === 1)
      return decodeURIComponent(vsStr);

    var sResult = new StringBuilder(decodeURIComponent(slSplit[0]));
    for (var i = 1; i < slSplit.length; ++i) {
      var sTmp = slSplit[i];
      var len = sTmp.length;
      if (len < 4)
        sResult.append("%u" + sTmp);
      else {
        var charCode = sTmp.substr(0, 4);
        sResult.append(String.fromCharCode(parseInt(charCode,16)));
        sResult.append(decodeURIComponent(sTmp.substr(4, sTmp.length-4)));
      }
    }
    return sResult.toString();
  }
  catch (e) {
    // Fallback to old-style encoding
    return unescape(vsStr);
  }
} 
   ;
}

</script></head>
<body>
<input onclick="ajaxreq()" type="button" value="Click me to load info!"></input>
<div id="info"></div>
</body>
</html>



我尝试过的事情:

我尝试使用substring和indexOf调用数据,但是我没有获取值..



What I have tried:

I have tried to call the data using substring and indexOf but i don''t get the values..

推荐答案

.ajax({ 网址:*一些链接* 错误:函数(jqxhr){ 警报(jqxhr.responseText); // @text =响应错误,它将是错误:324、500、404或其他任何内容 }, dataType:' html', 成功:功能(数据){ 警报(数据); 控制台 .log(数据); var coding = sDecodeURI(data); 控制台 .log(解码); }, 类型:' post' }) 函数 sDecodeURI(vsStr) { 调试器 尝试 { 如果( typeof (vsStr)!== " 字符串") 返回 vsStr; var slSplit = vsStr.split(' %u'); 如果(slSplit.length === 1 ) 返回 encodeURIComponent(vsStr); var sResult = StringBuilder(decodeURIComponent(slSplit [ 0 ])); for ( var i = 1 ; i < slSplit.length; ++ i){ var sTmp = slSplit [i]; var len = sTmp.length; 如果(len< 4 ) sResult.append(" + sTmp); 其他 { var charCode = sTmp.substr( 0 4 ); sResult.append(字符串 .fromCharCode( parseInt (charCode, 16 )))); sResult.append(decodeURIComponent(sTmp.substr( 4 ,sTmp.length-4))); } } 返回 sResult.toString(); } 捕获(e){ // 后退到旧式编码 返回 转义(vsStr); } } ; } < / 脚本 > < /head < 正文 > < 输入 =" ajaxreq()" 类型 按钮" 点击我加载信息!" ">< /输入 > < div =" info" < > < /body > < /html >
.ajax({ url: *some link* error: function(jqxhr) { alert(jqxhr.responseText); // @text = response error, it is will be errors: 324, 500, 404 or anythings else }, dataType:'html', success: function(data) { alert(data); console.log(data); var decoding = sDecodeURI(data); console.log(decoding); }, type: 'post' }) function sDecodeURI(vsStr) { debugger try { if (typeof(vsStr) !== "string") return vsStr; var slSplit = vsStr.split('%u'); if (slSplit.length === 1) return decodeURIComponent(vsStr); var sResult = new StringBuilder(decodeURIComponent(slSplit[0])); for (var i = 1; i < slSplit.length; ++i) { var sTmp = slSplit[i]; var len = sTmp.length; if (len < 4) sResult.append("%u" + sTmp); else { var charCode = sTmp.substr(0, 4); sResult.append(String.fromCharCode(parseInt(charCode,16))); sResult.append(decodeURIComponent(sTmp.substr(4, sTmp.length-4))); } } return sResult.toString(); } catch (e) { // Fallback to old-style encoding return unescape(vsStr); } } ; } </script></head> <body> <input onclick="ajaxreq()" type="button" value="Click me to load info!"></input> <div id="info"></div> </body> </html>



我尝试过的事情:

我尝试使用substring和indexOf调用数据,但是我没有获取值..



What I have tried:

I have tried to call the data using substring and indexOf but i don''t get the values..


这篇关于如何在javascript中将元素值(sid和stmp值)作为键值对调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆