2014-04-04 43 views
0

我知道這已被問過很多次,但在閱讀所有解決方案後,我仍然無法找到解決此問題的方法。我從最近4個小時就停留在這一點上,所以任何幫助都會真正被讚賞。 這裏是我的Ajax調用:無效的Web服務調用,參數缺失值:'newReviewOrLike'

 $.ajax({ 
      url: "http://localhost:1316/MoviesWebService.asmx/saveReview", 
      data: '{ username:"kartik1990",critic:"sanjayR",quote:"great",imdbId:"tt189",isCriticAMember:"true",reviewOrLikes:"review" }', 
      type: 'post', 
      contentType: 'application/json', 
      dataType:'json', 
      success: function (response) { 
       console.log(response); 
      } 
     }); 

ASMX代碼:

[WebMethod] 
public bool saveReview(ProjLikesTO newReviewOrLike) { 
    using (kkapilaCSDataContext db = new kkapilaCSDataContext()) { 
     proj_like action = new proj_like(); 
     action.username = newReviewOrLike.username; 
     action.critic = newReviewOrLike.critic; 
     action.quote = newReviewOrLike.quote; 
     action.imdbId = newReviewOrLike.imdbId; 
     action.isCriticAMember = newReviewOrLike.isCriticAMember; 
     action.reviewOrlikes = newReviewOrLike.reviewOrLikes; 
     db.proj_likes.InsertOnSubmit(action); 
     db.SubmitChanges(); 
     return true; 
    } 

ProjLikesTO:

public class ProjLikesTO { 
    public string username { 
     set; 
     get; 
    } 
    public string critic { 
     set; 
     get; 
    } 
    public string quote { 
     set; 
     get; 
    } 
    public string imdbId { 
     set; 
     get; 
    } 
    public string isCriticAMember { 
     set; 
     get; 
    } 
    public string reviewOrLikes { 
     set; 
     get; 
    } 

    public ProjLikesTO() { 
    } 

    public ProjLikesTO(string username, string critic, string quote, string imdbId, string isCriticAMember, string reviewOrLikes) { 
     this.username = username; 
     this.critic = critic; 
     this.quote = quote; 
     this.imdbId = imdbId; 
     this.isCriticAMember = isCriticAMember; 
     this.reviewOrLikes = reviewOrLikes; 
    } 

} 

回答

0

在你的情況首先你必須用ajax傳遞之前填充對象,如圖低於

var newReviewOrLike = { username:"kartik1990",critic:"sanjayR",quote:"great",imdbId:"tt189",isCriticAMember:"true",reviewOrLikes:"review" } 
    $.ajax({ 
      url: "http://localhost:1316/MoviesWebService.asmx/saveReview", 
      data: JSON.stringify({ newReviewOrLike : newReviewOrLike }), 
      type: 'post', 
      contentType: 'application/json', 
      dataType:'json', 
      success: function (response) { 
       console.log(response); 
      } 
     }); 
+1

它的工作..!非常感謝。 – user3291389

+0

我的榮幸@ user3291389 :) – Neel

0

你需要對你的ajax方法進行一些更改..

var newReviewOrLike= { username:"kartik1990",critic:"sanjayR",quote:"great",imdbId:"tt189",isCriticAMember:"true",reviewOrLikes:"review" }; 

    $.ajax({ 
      url: "http://localhost:1316/MoviesWebService.asmx/saveReview", 
      data: JSON.stringify({'newReviewOrLike':newReviewOrLike}), // check this 
      type: 'post', 
      contentType: 'application/json', 
      dataType:'json', 
      success: function (response) { 
       console.log(response); 
      } 
     }); 
相關問題