c#WebDevice的ajax参数

c#WebDevice的ajax参数,c#,ajax,parameters,C#,Ajax,Parameters,我有一个webservice函数helloworld(stringstr),我想用js调用它。如何将参数从js传递到HelloWorld?我的代码如下。非常感谢 //js中的代码 function BindJson() { $.ajax({ type: 'GET', url: 'Service1.asmx?op=HelloWorld', data: {str: 'asdasdas'}, contentType: "ap

我有一个webservice函数helloworld(stringstr),我想用js调用它。如何将参数从js传递到HelloWorld?我的代码如下。非常感谢

//js中的代码

function BindJson() {

    $.ajax({
        type: 'GET',
        url: 'Service1.asmx?op=HelloWorld',

        data: {str: 'asdasdas'},

        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data1) {
            alert('suc    ' + data1.d);
        },
        error: function (request, status, errorThrown) {
            alert('err    ' + status + errorThrown);
        }
    });
}

$(document).ready(function() {
    BindJson();    
});
//c#webservice中的代码

[WebMethod]
        public void HelloWorld(string str)
        {
            StreamWriter _testData = new StreamWriter(Server.MapPath("~/data.txt"), true);
            _testData.WriteLine(str); // Write the file.
            _testData.Flush();
            _testData.Close(); // Close the instance of StreamWriter.
            _testData.Dispose(); // Dispose from memory.       
        }

?op=是通过浏览器测试Web服务的操作参数您可以使用“Service1.asmx/HelloWorld”而不是Service1.asmx/?op=HelloWorld

请参阅一次,它可能会有所帮助..试试Post:首先谢谢大家。我尝试了你告诉我的一切,但都没有成功。我尝试过,但得到了“内部服务器错误”的消息,这意味着发生错误:函数。