rinku rawat

rinku rawat

  • NA
  • 131
  • 18.6k

Ajax call for Web API

Mar 18 2019 6:28 AM
Hi,
 
How can we pass array type data from ajax to web API.
 
Web API -
public HttpResponseMessage SearchFileByIDs([FromBody]string[] values)
{
.....
....
...
}
 
Ajax call -
  1. <script type="text/javascript">  
  2. $(function () {  
  3. $("#btnGet").click(function () {  
  4. debugger;  
  5. let fruits = ["5c86296afce2d453a8c27d1c""5c86285cfbaa888204f38fd1"];  
  6. //alert(fruits);  
  7. $.ajax({  
  8. url: 'http://localhost:8082/api/v1/SearchByIDS',  
  9. type: 'POST',  
  10. dataType: 'json',  
  11. data:"="+ fruits,  
  12. success: function (data, textStatus, xhr) {  
  13. debugger;  
  14. console.log(data);  
  15. // alert(data.Data.FileUrl);  
  16. },  
  17. error: function (xhr, textStatus, errorThrown) {  
  18. console.log('Error in Operation');  
  19. }  
  20. });  
  21. });  
  22. });  
  23. </script> 
We get fruits id in web api parameter values -
 

Answers (3)