私はAJAXとC#を初めて使用していますので、一緒に作業する方法を試しています。私はWebアプリケーションを構築しています。私はajax関数でC#のメソッドを呼び出しています。すべて正常に動作すれば、私はC#クラスに成功メッセージを返します。どうやってやるの? これは私のAjaxの方法C#でajaxレスポンスを返すには?
<script type="text/javascript">
Hello();
function Hello() {
$.ajax({
type: "POST",
url: "Dtata.aspx/Hello",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
response(result.d);
},
error: function (result) {
alert('There is a problem processing your request');
}
});
}
</script>
//Basically I want to know the success/failure value from the Ajax call and print it back to my console.
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string Hello(string name)
{
return name;
}
を私はあなたが逃したと思いますあなたのajax呼び出しで文字列名を渡すために.. $ .ajax({ タイプ: "POST"、 url: "Dtata.aspx/Hello"、 contentType: "application/json; charset = utf-8 "; データ型:" json "、データ:{名前: 'hello'} 成功:関数(結果){ 応答(result.d); }、 エラー:関数(結果){ アラート( 'あなたのリクエストを処理する際に問題があります'); } }); –
循環リクエスト/応答を作成しようとしています。 C#Webメソッドから送信された応答は、AJAXの成功につながります。これをサーバーに再送しようとしています。 –