Use Flash and XML to build Forum instances (4)

Source: Internet
Author: User
C. Asp end

Create an Asp file named newreply. asp and add the following content:

<%
Set MyFileObject = Server. CreateObject ("Scripting. FileSystemObject") 'comment 1
Set MyTextFile = MyFileObject. CreateTextFile ("G: \ writing \ flashxmlbbs \ login. xml", 8, TRUE)
MyTextFile. WriteLine (Request. Form)

Set objDom = server. CreateObject ("microsoft. xmldom") 'comment 2
ObjDom. loadxml (Request. Form)
Set objID = objdom.doc umentElement. SelectSingleNode ("// NEW/ID") 'comment 3
Id = objID. text
Set objTitle = objdom.doc umentElement. SelectSingleNode ("// NEW/TITLE ")
Title = objTitle. text
Set objAuthor = objdom.doc umentElement. SelectSingleNode ("// NEW/NAME ")
Author = objAuthor. text
Set objContent = objdom.doc umentElement. SelectSingleNode ("// NEW/FILE ")
Content = objContent. text

'Judge
Set conn = Server. CreateObject ("ADODB. Connection") 'comment 4
Conn. open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("/xmlbbs. mdb ")
Sqltemp = "insert into FileInfo (title, author, fid, content) values ('" & Title & "', '" & Author & "'," & id &", '"& Content &"') "'comment 5
Conn. Execute (sqltemp)
Conn. close

'Back
Response. write ("<BACK flag1 =" "1" "> </BACK>") 'comment 6
%>
 
Note 1: create a temporary file to leave debugging marks on the server side.

NOTE 2: Create an XML object.

NOTE 3: Read the content of the ID, TITLE, NAME, and FILE nodes respectively.

Note 4: Create An ADO connection for a database.

Note 5: Construct an SQL statement to insert data.

Note 6: return the constructed XML string.

6. Delete

Delete: the server receives the ID number from the Flash end, deletes the corresponding records in the database, and returns results in XML format.

A. Passed XML

1. Request Message

<DEL> <ID> ID to be deleted </ID> </DEL>

2. Response Message

<BACK flag1 = "1"> </BACK>

B. Flash end

1. Return the third frame of the scenario. Add a Button with the displayed content "delete" in the scenario, and add the following statement on the Action Script Panel of the Button:

On (release ){
DelXml = new XML (); file: // Note 1
DelElement = delXml. createElement ("DEL"); file: // comment 2
IdElement = delXml. createElement ("ID"); file: // comment 3
IdNode = delXml. createTextNode ("id ");
IdNode. nodeValue = _ root. fileNowId;
IdElement. appendChild (idNode); file: // comment 4
DelElement. appendChild (idElement );
DelXml. appendChild (delElement );

DelRepley = new XML (); file: // comment 5
DelRepley. onLoad = onDelReply;
Function onDelReply (delsuccess ){
If (delsuccess ){
}
}
DelXml. sendAndLoad ("http: // localhost/xmlbbs/del. asp", delRepley); file: // comment 6
}
 
Note 1: Create an XML object.

NOTE 2: Create a DEL Node object.

NOTE 3: Create an ID Node object and add content.

Note 4: add the created Node object to the XML object.

Note 5: Create an XML object for the response.

Note 6: Send an XML object to the server and receive the returned results.

C. Asp end

<%
Set MyFileObject = Server. CreateObject ("Scripting. FileSystemObject") 'comment 1
Set MyTextFile = MyFileObject. CreateTextFile ("G: \ writing \ flashxmlbbs \ login. xml", 8, TRUE)
MyTextFile. WriteLine (Request. Form)

Set objDom = server. CreateObject ("microsoft. xmldom") 'comment 2
ObjDom. loadxml (Request. Form)
Set objid = objdom.doc umentElement. SelectSingleNode ("// DEL/ID") 'comment 3
Id = objid. text

'Judge
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("/xmlbbs. mdb ")
Set rs = Server. CreateObject ("ADODB. Recordset ")
Sqltemp = "delete from FileInfo where id =" & id & "or fid =" & id' comment 4
Conn. Execute (sqltemp)
Conn. close

'Back
Response. write ("<BACK flag1 =" "1" "> </BACK>") 'comment 5
%>
 
Note 1: Construct a temporary file and write the content to it for debugging.

NOTE 2: Construct an XML Object Based on the XML string of the Flash end.

NOTE 3: Obtain the content of the ID node.

Note 4: Construct a deleted SQL string.

Note 5: return the constructed XML string to the Flash end.

VII. Summary

This example implements a forum framework that mainly involves the interpretation of XML objects between Flash and Asp and the transmission of XML strings. If this principle is unclear, refer to the previous article.

The example implemented in this article may be a little difficult for friends with poor programming skills. You can use the source file and try it several times, so be patient. If there is any proposal or a better way to achieve it, you can write me E-mail: zengyu111@sohu.com

FAQ appendix:

1. Development Environment Introduction

This article is developed in the windows advance server 2000 + IIS 5.0 + notepad + Flash MX 2004 environment.

2. How to interpret XML in asp

Microsoft's ms xml package allows you to easily interpret and generate XML objects.

3. How does one send XML objects in Flash?

The sendAndLoad () function in Flash uses the POST method to send XML objects to the server, so the Asp side can use Request. Form to obtain the XML format string sent. Writing the transmitted XML object in a temporary file is a very effective debugging method.

4. data format in the database used in this article

This document uses the Access 2000 database and uses two tables:

UserInfo table: ID, username, userpwd, userright
FileInfo table: ID, title, author, fid, content

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.