最近在做一个项目,用到了AJAX PRO2的这个组件,但一直无法成功使用,总是没有结果返回,请各位高手帮忙解决.
代码如下:
AJAX.ASPX.CS
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
using coladata;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;[AjaxPro.AjaxNamespace("Ajaxmap")]
public partial class ajax2 : System.Web.UI.Page
{
private double tempid, tempX, tempY;
private string tempname, tempadd, tempso, tempsales, tempsalesno;
private string sql; [AjaxPro.AjaxMethod]
public string GetServerTime(string str)
{
return str;
} protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax2)); /// <summary>
///设置代理
/// <summary>
WebProxy proxy = new WebProxy("proxy.cccil.com", 8000);
proxy.Credentials = new NetworkCredential("km35609", "qwe1234!", "proxy.cccil.com"); ///DO SOMETHING } objds.Dispose(); }
}AJAX2.ASPX<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax2.aspx.cs" Inherits="ajax2" %><!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" runat="server" name="ok" onclick="showdata();" value="test"/>
</div>
</form>
</body>
</html><script language="javascript">
function showdata(){
var str="linux";
ajax2.GetServerTime(str,result);}function result(val){
alert(val.value);
}
</script>配置文件:
<?xml version="1.0"?>
<configuration> <configSections>
<sectionGroup name="ajaxNet"> <!--
If you are using Microsoft .NET 1.1 please remove the two attributes
requirePermission and restartOnExternalChanges, they are only supported
with .NET 2.0.
-->
<section name="ajaxSettings"
type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2"
requirePermission="false"
restartOnExternalChanges="true"
/> </sectionGroup>
</configSections> <ajaxNet>
<ajaxSettings> <urlNamespaceMappings useAssemblyQualifiedName="false">
<!--
Set the attribute useAssemblyQualifiedName to true to enable
use of assemblies placed in the GAC by using the full assembly
qualified name.
To hide internal knowledge of assemblies, classes and namespace
you can override the name of the virtual http endpoints.
<add type="Namespace.Class1,Assembly" path="mypath" />
-->
</urlNamespaceMappings> <jsonConverters>
<!--
This section can be used to add new IJavaScriptConverters to the
Ajax.NET Professional engine. If you want to disable built-in
converters you can use the remove tag.
<remove type="Namespace.Class1,Assembly"/>
<add type="Namespace.Class2,Assembly"/>
-->
</jsonConverters> <!--
Set the enabled attribute to true to get Stack, TargetSize and Source
information if an exception has been thrown.
-->
<debug enabled="false" /> <!--
This is the default configuration used with Ajax.NET Professional. You
can put there your static JavaScript files, or remove the path attribute
to completly disable the files.
<scriptReplacements>
<file name="core" path="~/ajaxpro/core.ashx" />
<file name="prototype" path="~/ajaxpro/prototype.ashx" />
<file name="converter" path="~/ajaxpro/converter.ashx" />
</scriptReplacements>
--> <!-- <encryption cryptType="" keyType="" /> --> <!--
Set the enabled attribute to true to enable the use of an Ajax.NET Professional
token. This will send a token to the client that will be used to identify if the
requests comes from the same PC.
-->
<token enabled="false" sitePassword="password" /> <!--
The oldStyle section can be used to enable old styled JavaScript code or
functions that are not used any more.
--> <oldStyle>
<includeMsPrototype/>
</oldStyle> </ajaxSettings>
</ajaxNet> <location path="ajaxpro">
<system.web>
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
<!--
If you need to have Ajax.NET Professional methods running on the
login page you may have to enable your own authorization configuration
here.
-->
<!--
<authorization>
<deny users="?"/>
</authorization>
-->
</system.web>
</location> <!--
If you are using Ajax.NET Professional with forms authentication you may need
to allow ASP.NET to have access to following three files.
-->
<!--
<location path="ajaxpro/prototype.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location> <location path="ajaxpro/core.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location> <location path="ajaxpro/converter.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
-->
</configuration>
代码如下:
AJAX.ASPX.CS
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
using coladata;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;[AjaxPro.AjaxNamespace("Ajaxmap")]
public partial class ajax2 : System.Web.UI.Page
{
private double tempid, tempX, tempY;
private string tempname, tempadd, tempso, tempsales, tempsalesno;
private string sql; [AjaxPro.AjaxMethod]
public string GetServerTime(string str)
{
return str;
} protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax2)); /// <summary>
///设置代理
/// <summary>
WebProxy proxy = new WebProxy("proxy.cccil.com", 8000);
proxy.Credentials = new NetworkCredential("km35609", "qwe1234!", "proxy.cccil.com"); ///DO SOMETHING } objds.Dispose(); }
}AJAX2.ASPX<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax2.aspx.cs" Inherits="ajax2" %><!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" runat="server" name="ok" onclick="showdata();" value="test"/>
</div>
</form>
</body>
</html><script language="javascript">
function showdata(){
var str="linux";
ajax2.GetServerTime(str,result);}function result(val){
alert(val.value);
}
</script>配置文件:
<?xml version="1.0"?>
<configuration> <configSections>
<sectionGroup name="ajaxNet"> <!--
If you are using Microsoft .NET 1.1 please remove the two attributes
requirePermission and restartOnExternalChanges, they are only supported
with .NET 2.0.
-->
<section name="ajaxSettings"
type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2"
requirePermission="false"
restartOnExternalChanges="true"
/> </sectionGroup>
</configSections> <ajaxNet>
<ajaxSettings> <urlNamespaceMappings useAssemblyQualifiedName="false">
<!--
Set the attribute useAssemblyQualifiedName to true to enable
use of assemblies placed in the GAC by using the full assembly
qualified name.
To hide internal knowledge of assemblies, classes and namespace
you can override the name of the virtual http endpoints.
<add type="Namespace.Class1,Assembly" path="mypath" />
-->
</urlNamespaceMappings> <jsonConverters>
<!--
This section can be used to add new IJavaScriptConverters to the
Ajax.NET Professional engine. If you want to disable built-in
converters you can use the remove tag.
<remove type="Namespace.Class1,Assembly"/>
<add type="Namespace.Class2,Assembly"/>
-->
</jsonConverters> <!--
Set the enabled attribute to true to get Stack, TargetSize and Source
information if an exception has been thrown.
-->
<debug enabled="false" /> <!--
This is the default configuration used with Ajax.NET Professional. You
can put there your static JavaScript files, or remove the path attribute
to completly disable the files.
<scriptReplacements>
<file name="core" path="~/ajaxpro/core.ashx" />
<file name="prototype" path="~/ajaxpro/prototype.ashx" />
<file name="converter" path="~/ajaxpro/converter.ashx" />
</scriptReplacements>
--> <!-- <encryption cryptType="" keyType="" /> --> <!--
Set the enabled attribute to true to enable the use of an Ajax.NET Professional
token. This will send a token to the client that will be used to identify if the
requests comes from the same PC.
-->
<token enabled="false" sitePassword="password" /> <!--
The oldStyle section can be used to enable old styled JavaScript code or
functions that are not used any more.
--> <oldStyle>
<includeMsPrototype/>
</oldStyle> </ajaxSettings>
</ajaxNet> <location path="ajaxpro">
<system.web>
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
<!--
If you need to have Ajax.NET Professional methods running on the
login page you may have to enable your own authorization configuration
here.
-->
<!--
<authorization>
<deny users="?"/>
</authorization>
-->
</system.web>
</location> <!--
If you are using Ajax.NET Professional with forms authentication you may need
to allow ASP.NET to have access to following three files.
-->
<!--
<location path="ajaxpro/prototype.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location> <location path="ajaxpro/core.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location> <location path="ajaxpro/converter.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
-->
</configuration>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货