@using System.Data
@model System.Data.DataTable
function onInputChange(event){
console.log(event.target.value);
if(event.target.value == ''){
const casArea = document.getElementById('div-cas');
const cases = casArea.getElementsByTagName('p');
for(let i = cases.length-1;i>0;i--){
cases[i].remove();
}
document.getElementById("cas").innerText = '';
document.getElementById("mw").innerText = '';
}
}
function loadCAS() {
var casArray = [];
const casArea = document.getElementById('div-cas');
const cases = casArea.getElementsByTagName('p');
for(let i = cases.length-1;i>0;i--){
cases[i].remove();
}
document.getElementById("cas").innerText = '';
document.getElementById("mw").innerText = '';
var flag = 1;
var searchurl = 'https://commonchemistry.cas.org/api/search?q='; // 获取 JSON 数据的链接
var request;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest(); //发送 Ajax 请求,适用于 Chrome, mozilla 等浏览器
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHTTP"); // 发送 Ajax 请求,适用于 IE 浏览器
}
var keyword = document.getElementById("keyword").value;
searchurl += encodeURIComponent(keyword);
request.open("GET", searchurl, false);
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var response = request.responseText;
console.log(JSON.parse(response));
let count = Number(JSON.parse(response).count.toString());
console.log("count="+ count);
if( count == 0){
document.getElementById("cas").innerText = '暂无数据';
flag = 0;
}
else{
console.log("cas01:"+JSON.parse(response).results[0].rn);
document.getElementById("cas").textContent = JSON.parse(response).results[0].rn;
casArray.push(JSON.parse(response).results[0].rn.toString());
for(let i = 1;i const newCas = document.createElement('p'); newCas.textContent = JSON.parse(response).results[i].rn; casArray.push(JSON.parse(response).results[i].rn.toString()); const casArea = document.getElementById('div-cas'); casArea.appendChild(newCas); } } }else if(request.readyState == 4 && request.status == 404){ } } request.send(); if(flag == 1){ for(let i = 0;i console.log("cas"+ i +":"+casArray[i]); } $.ajax({ url: '/HomeController/Index', method: 'POST', data: { casArray: JSON.stringify(casArray) }, success: function(response){ console.log("请求成功"); }, error: function(error){ console.log("请求失败"); } }); loadMW(); } } function loadMW(){ var detailurl = 'https://commonchemistry.cas.org/api/detail?cas_rn='; // 获取 JSON 数据的链接 var request; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); //发送 Ajax 请求,适用于 Chrome, mozilla 等浏览器 } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); // 发送 Ajax 请求,适用于 IE 浏览器 } var cas = document.getElementById("cas").innerText.toString(); console.log('loadMW-cas:'+cas); detailurl += encodeURIComponent(cas); request.open("GET", detailurl, false); request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { var response = request.responseText; console.log(JSON.parse(response)); document.getElementById("mw").innerHTML = JSON.parse(response).molecularMass; }else if(request.readyState == 4 && request.status == 404){ } } request.send(); } CAS:
MW:
分类 | 名称 | CAS |
---|---|---|
@row["category"] | @row["name"] | @row["cas"] |