jquery调用wcf并展示出数据的方法

2020-05-19 07:42:38易采站长站整理

var html = ‘<li><a href=”http://meinv.vs2010.com/topic/’%20+%20$(this).children(“Body_MuLuID”).text() + ‘/’ + rq + ‘/show-id’ + $(this).children(“Body_ID”).text() + ‘.html” target=”_blank”><img src=”http://meinv.vs2010.com/’%20+%20$(this).children(“Body_Tu”).text() + ‘” />’ + $(this).children(“Body_Name”).text() + ‘</a></li>’;
$(“.main ul”).append(html);
});
});
}

$(function () {
sendAJAX();
});
</script>
<div id=”msg”>
</div>
</div>
</form>
</body>
</html>

说明一下,主要是通过jquery的getjson方法去取得wcf返回的数据,传参方法:
$.getJSON(url, { pz: “6” }, function (msg) {alert(msg.d)});这里是返回6条数据还有wcf的svc上加上属性:
Factory=System.ServiceModel.Activation.WebScriptServiceHostFactory还有web.config的配置:

<?xml version=”1.0″?>
2 <configuration>
3
4 <configSections>
5 <!–ajax–>
6 <sectionGroup name=”ajaxNet”>
7 <section name=”ajaxSettings” type=”AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2″ requirePermission=”false” restartOnExternalChanges=”true”/>
8 </sectionGroup>
9 <!–ajax–>
<sectionGroup name=”system.web.extensions” type=”System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″>
<sectionGroup name=”scripting” type=”System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″>
<section name=”scriptResourceHandler” type=”System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication”/>
<sectionGroup name=”webServices” type=”System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″>
<section name=”jsonSerialization” type=”System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”Everywhere” />
<section name=”profileService” type=”System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication” />