开发者

Calling rest uri in javascript using asp.net?

I am able to call the rest service uri on the server side button click event of a aspx button.

private void Insert(InsertEmployee obj) { try { uri = "http://localhost:3324/Issues.svc/ADD/"; using (HttpResponseMessage response = new HttpClient().Post(uri, HttpContentExtensions.CreateDataContract(obj))) {

  int iStatus = response.Content.ReadAsDataContract<int>();
  if (iStatus > 0)
  lblErr.Text = "Record Inserted";
  else
  lblErr.Text = "Insertion Failed";

}
}
catch (Exception)
{

throw;
}
}

The above is the method I call to insert records which is working.

Can u help me how to call this method in ajax.I tried the below code but not working.Even if I run this link in browser http://localhost:3324/Issues.svc/ADD/ this is not working says method not found.

function CreateEmployee() { alert("S"); var strService = "http://localhost:3324/Issues.svc/ADD/"; $.ajax({ "type": "POST", "url": strService, "dataType": 'jsonp', "data": {"code":"101","empname":"Test140","mode":"I"}, success: function(json) { alert(json); 开发者_开发百科 //result = jQuery.parseJSON( json ); }, error: ServiceFailed// When Service call fails

} ); }


If you are using a WCF - REST service , do look into this msdn article.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜