2016-06-29 6 views
2

サーバー側からjsonデータを取得できません。スクリプトはサーバーメソッドを呼び出しますが、jsonデータは返されません。あなたは `HTTPを必要といけないjson ajaxリクエストをWeb APIに投稿するには

$(document).ready(function() { 
    $("#SendMail").click(function() { 
     $.ajax({ 
      url: "http://localhost:2457/SendMail/SendMail/", 
      dataType: 'json', 
      type: 'POST', 
      data: "{htmlTemplate:" + "ABC" + "}", 
      //crossDomain: true, 
      //contentType: "application/json; charset=utf-8", 
      success: function(data, textStatus, xhr) { 
       console.log(data); 
       alert('Successfully called'); 
      }, 
      error: function(xhr, textStatus, errorThrown) { 
       // console.log(errorThrown); 

      } 
     }); 
    }); 
}); 

Function SendMail(htmlTemplate As String) As String 
     Dim fname As String = Request.Form("htmlTemplate1") 
     Dim lname As String = Request.Form("lname") 
     Dim cmdSendMail As New SendMailCommand() 
     Return "A" 
    End Function 
+0

:// localhostを:2457年には、/'唯一のサービス名は、同様に 'webapi'方法を提供 – brk

+0

十分でしょう。 – Venky

+0

WebApiコントローラのデフォルトのルートは、/ api/{Controller}/{Action} –

答えて

0
<script> 
$(document).ready(function() { 
     $("#SendMail").click(function() { 
      $.ajax({ 
       url: '/SendMail/SendMail/', 
       dataType: 'text', 
        type: 'POST', 
        data:JSON.stringify({htmlTemplate: "ABC"}), 
       //crossDomain: true, 
       contentType: "application/json; charset=utf-8", 
       success: function (data, textStatus, xhr) { 
       console.log(data); 
        alert('Successfully called'); 
       }, 
       error: function (xhr, textStatus, errorThrown) { 
        console.log(errorThrown); 
       } 
      }); 
     }); 
    }); 
</script> 
関連する問題