Avatar of ITsolutionWizard
ITsolutionWizard
Flag for United States of America asked on

js datatable

hi experts. can you show me super simple demo with mvc web api (without entity framework)  that using js datatable?
I have some troubles on the ajax part. The web api is showing data in the browser but I have some trouble to call web api in ajax jquery.
JavaScriptjQueryAJAX

Avatar of undefined
Last Comment
Mrunal

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Brian M

Can you post the code you are using?
Mrunal

Hi
I hope you are done with developing web api as you are getting response on browser.
For calling web api from Ajax below is syntax:

<script>  
    $(document).ready(function () {  
        $.ajax({  
            type: "GET",  
            url: "<your_api_path_here>",  
            contentType: "application/json; charset=utf-8",  
            dataType: "json",  
            success: function (data) {  
                //alert(JSON.stringify(data));
                //process your data here
            },  
            failure: function (data) {  
                alert(data.responseText);  
            },
            error: function (data) {  
                alert(data.responseText);  
            }  
        });         
    });  
</script>

Open in new window


Here is reference:

http://api.jquery.com/jquery.ajax/
ITsolutionWizard

ASKER
thanks. will the codes work with cross domain?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Mrunal

For cross domain requests, some code changes are required. Above will not work in that case.
Please search on CORS with jquery ajax.
More information is at:
https://zinoui.com/blog/cross-domain-ajax-request

Hope this solves your problem.