webservice webmethod无法正常工作 [英] webservice webmethod not working

查看:105
本文介绍了webservice webmethod无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="extra.aspx.vb" Inherits="dropdownBind.extra" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Bind Dropdownlist with JQuery in asp.net</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
           url: "extra.aspx/BindDatatoDropdown",
             data: "{}",
            dataType: "json",
            success: function (data) {
                $.each(data.d, function (key, value) {
                    $("#ddlCountryd").append($("<option></option>").val(value.CountryId).html(value.CountryName));
                });
            },
            error: function (result) {
                alert("Error");
            }
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DropDownList ID="ddlCountryd" runat="server" />
    </div>
    </form>
</body>
</html>

______________________________________________

______________________________________________

Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services

Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Text.RegularExpressions
Imports System.Collections
Imports System.Diagnostics
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Net
Imports System.Threading
Imports System.Web.Services.Protocols
Imports System.Globalization
Imports System.Web.Script.Serialization
Imports System.Web.Configuration

<system.web.script.services.scriptservice>
Public Class extra
    Inherits System.Web.UI.Page

    Public Shared webService As New webSer.Service1

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

 <webmethod()> _
    Public Shared Function BindDatatoDropdown() As CountryDetails()
        Dim dt As New DataTable()
        Dim details As New List(Of CountryDetails)()
        Dim branchCode As String = "002"
        Dim strCon As String = "002_001;"
        Dim dst As New DataSet()
        dst = webService.getCustomerDs(branchCode, strCon)
        dt = dst.Tables(0)
      
            For Each dtrow As DataRow In dt.Rows
                Dim country As New CountryDetails()
                country.CountryId = dtrow("custcode").ToString()
                     country.CountryName = dtrow("customer").ToString()
                details.Add(country)
            Next

            Return details.ToArray()
    End Function

    Public Class CountryDetails
        Public Property CountryId() As String
            Get
                Return m_CountryId
            End Get
            Set(ByVal value As String)
                m_CountryId = value
            End Set
        End Property
        Private m_CountryId As String
        Public Property CountryName() As String
            Get
                Return m_CountryName
            End Get
            Set(ByVal value As String)
                m_CountryName = value
            End Set
        End Property
        Private m_CountryName As String
    End Class

End Class



--------------- ---------------------------------------------



这里,webservice从托管服务。



如果我们从本地提供sql命令(即select * from ___),它就可以工作了。



如果是来自webservice,则无效。请帮助。


------------------------------------------------------------

Here, webservice calling from hosted.

If we are giving sql command from local (i.e "select * from ___ "), it is working.

If it is from webservice, it is not working. Please help.

推荐答案

document )。ready( function (){
(document).ready(function () {


.ajax({
type: POST
contentType: application / json; charset = utf- 8
url: extra.aspx / BindDatatoDropdown
数据: {}
dataType: json
成功:功能(数据) {
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "extra.aspx/BindDatatoDropdown", data: "{}", dataType: "json", success: function (data) {


.each(data.d, function (key,value){
.each(data.d, function (key, value) {


这篇关于webservice webmethod无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆