2016-04-10 13 views
0

JavaScriptを使用して実装する必要がありました。本文をモデルに投稿する

私はこのクラスを持っている:

Public Class RecommendedJobsData 
    Public Property searchedJobsList As List(Of JobInfo) 
    Public Property jobFromStorage As JobInfo 
    Public Property totalJobsCount As Integer 
    Public Property adType As AdType 

    Public Sub New() ' default constructor 

    End Sub 

    ' constructor with parameters 
    Public Sub New(searchedJobsList As List(Of JobInfo), jobFromStorage As JobInfo, totalJobsCount As Integer, adType As AdType) 
     Me.searchedJobsList = searchedJobsList 
     Me.jobFromStorage = jobFromStorage 
     Me.totalJobsCount = totalJobsCount 
     Me.adType = adType 
    End Sub 
End Class 

私はこの関数にPOSTリクエストを送信しようとしています:

<JsonpFilter()> 
Public Function GetToken(header As RequestHeader, body As RecommendedJobsData) As String 

    Return String.Empty 

End Function 

だから私はJavaScriptを使用:

var http = new XMLHttpRequest(); 

http.open("POST", url, true); 

//Send the proper header information along with the request 
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 

http.onreadystatechange = function() {//Call a function when the state changes. 
    if (http.readyState == 4 && http.status == 200) { 
     alert(http.responseText); 
    } 
} 
http.send(apiParams); 

ヘッダがあります罰金は合格しましたが、体はそうではありません。

パラメータを取得するコンストラクタの代わりにデフォルトのコンストラクタが入力され、本体オブジェクトにnull値があると、GetToken関数が機能します。

これはapiParamsです:

enter image description here

すべてのヘルプ感謝!

答えて

0

は私がするコンテンツタイプを変更した:

http.setRequestHeader("Content-type", "application/json"); 

そして私は、送信機能変更:

http.send(JSON.stringify(apiParams)); 

そして、最も重要なことは、次のとおりです。

<FromBody()>属性でのGetToken関数:

Public Function GetToken(header As RequestHeader, 
<FromBody()> body As RecommendedJobsData) 

system.web.httpへの参照を追加することに注意してください。

関連する問題