DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解
ASP + XMLHTTP 新聞接口文件格式完整說明
編輯:AJAX詳解     

接口 XML 文件格式

本接口採用標準 XML 結構封裝新聞數據,最外層以 <info> 標籤包裹,內部每一則新聞對應一個 <rec> 節點。各字段含義如下:

<info>
  <rec>
    <depID>所屬欄目</depID>
    <smallClassID>所屬信息單位</smallClassID>
    <type>信息發布形式</type>
    <keyWord>關鍵字</keyWord>
    <title>新聞標題</title>
    <author>作者</author>
    <original>原出處</original>
    <content>新聞內容</content>
  </rec>
  <rec>
    ...(可包含多則新聞)
  </rec>
</info>

字段類型與取值說明

字段名名稱類型取值說明上傳說明
depID所屬欄目Int(4)代碼不能為空
smallClassID所屬信息單位Nvarchar(25)代碼不能為空
type信息發布形式Nvarchar(7)重要信息=1;彈出信息=2;熱點信息=3,可複選多個並以「,」分隔,如:1,2,3代碼(多個用逗號分隔)
keyWord關鍵字Nvarchar(50)多個以「,」分隔,如:keyWord1,keyWord2文字(多個用逗號分隔)
title新聞標題Nvarchar(50)文字不能為空
author作者Nvarchar(20)文字文字
original原出處Nvarchar(20)文字文字
content新聞內容varChar(4000)文字不能為空

格式範例

<info>
  <rec>
    <depID>1</depID>
    <smallClassID>20040212200856429814</smallClassID>
    <type>1,3</type>
    <keyWord>關鍵字1, 關鍵字2</keyWord>
    <title>新聞標題</title>
    <author>作者</author>
    <original>原出處</original>
    <content>新聞內容</content>
  </rec>
</info>

上傳方法說明

將上述生成的字符串以 POST 方式發送至 https://服務器IP:端口/receiveInfo.ASP(務必使用 POST 傳送)。以下為經測試通過的完整代碼。

發送端 sendInfo.ASP

<%
set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
XMLstr = "<info><rec><depID>1</depID><smallClassID>20040212200856429814</smallClassID><type>1,3</type><keyWord>關鍵字1, 關鍵字2</keyWord><title>新聞標題</title><author>作者</author><original>原出處</original><content>新聞內容</content></rec></info>"
URL = "https://192.168.1.5:9020/receiveInfo.ASP"
XMLhttp.open "POST", URL, False
xmlhttp.send XMLstr
if err.number = 0 then
    if XMLhttp.status <> "200" then
        Response.Write "<font style='font-size:12px;color:red'>狀態:" & XMLhttp.status & " ;描述:" & XMLHttp.ResponseText & "</font>"
    else
        Response.Write "<font style='font-size:12px;color:red'> " & XMLHttp.ResponseText & "</font>"
    end if
else
    Response.Write "<font style='font-size:12px;color:red'>狀態:" & XMLhttp.status & " ;描述:" & XMLHttp.ResponseText & "</font>"
end if
%>

接收端 receiveInfo.ASP

<%@codepage=936%>
<%
Server.ScriptTimeOut = 99999
Response.Buffer = false
Response.CharSet = "gb2312"
set xmldoc = Server.CreateObject("MSXML2.DOMDocument")
XMLdoc.load Request
set root = XMLdoc.DocumentElement
for i = 1 to XMLdoc.documentelement.childNodes.length
    Set recnote = XMLdoc.documentelement.childNodes(i-1)
    Set depIDnote = recnote.selectSingleNode("depID")
    Set smallClassIDnote = recnote.selectSingleNode("smallClassID")
    Set typenote = recnote.selectSingleNode("type")
    Set keyWordnote = recnote.selectSingleNode("keyWord")
    Set titlenote = recnote.selectSingleNode("title")
    Set authornote = recnote.selectSingleNode("author")
    Set originalnote = recnote.selectSingleNode("original")
    Set contentnote = recnote.selectSingleNode("content")

    response.Write depIDnote.text & "||"
    response.Write smallClassIDnote.text & "||"
    response.Write typenote.text & "||"
    response.Write keyWordnote.text & "||"
    response.Write titlenote.text & "||"
    response.Write authornote.text & "||"
    response.Write originalnote.text & "||"
    response.Write contentnote.text & "||"
next
response.Write("0")
%>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved