AjAX Exploration -- JS calls to entity classes and assignment

Source: Internet
Author: User

BookInfo. cs
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;

Namespace ClassProj
{
[Serializable]
Public class BookInfo
{
Public BookInfo (){}

// In VS2008, you can use the following simplified method to define attributes. Is it easy ?!
Public string Name {set; get ;}
Public string Author {set; get ;}
Public int Price {set; get ;}
}
} Book. asmx. cs
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Services;
Using System. Web. Services. Protocols;
Using System. Xml. Linq;
Using System. Web. Script. Services;
Using ClassProj;

Namespace Test
{
/** // <Summary>
/// Summary of the Book
/// </Summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
[ToolboxItem (false)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
[ScriptService]
[GenerateScriptType (typeof (BookInfo)]
Public class Book: System. Web. Services. WebService
{

[WebMethod]
Public string ShowInfo (BookInfo book)
{
Return "the book information is as follows -- title:" + book. Name + ", Price:" + book. Price + "Author:" + book. Author;
}
}
} Test. js
Function ShowInfo ()
{
Var book = new ClassProj. BookInfo ();
Book. Name = "conquer AJAX! ";
Book. Price = 25;
Book. Author = "dream ";

Test. Book. ShowInfo (book, CallBack_Function );
}

Function CallBack_Function (ResponseStr)
{
$ Get ("result"). innerText = ResponseStr;
} AjaxStudy. aspx. cs
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "AjaxStudy02.aspx. cs" Inherits = "Test. AjaxStudy02" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: ScriptManager ID = "ScriptManager1" runat = "server">
<Scripts>
<Asp: ScriptReference Path = "~ /JsFile/Test. js "/>
</Scripts>
<Services>
<Asp: ServiceReference Path = "~ /Book. asmx "/>
</Services>
</Asp: ScriptManager>
<Input id = "Button1" type = "button" value = "test" onclick = "ShowInfo ();"/>
<Div id = "result"> </div>
</Div>
</Form>
</Body>
</Html>
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.