Click here to Skip to main content
15,884,237 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Session Automatically Expires After 55 to 60 Seconds In ASP.NET MVC With WEB API Pin
Vasudevan Deepak Kumar2-Apr-15 22:57
Vasudevan Deepak Kumar2-Apr-15 22:57 
AnswerRe: Session Automatically Expires After 55 to 60 Seconds In ASP.NET MVC With WEB API Pin
jkirkerx3-Apr-15 7:05
professionaljkirkerx3-Apr-15 7:05 
AnswerRe: Session Automatically Expires After 55 to 60 Seconds In ASP.NET MVC With WEB API Pin
Member 115596118-Apr-15 18:30
Member 115596118-Apr-15 18:30 
QuestionSetting Textbox value using JQuery Pin
indian1431-Apr-15 12:10
indian1431-Apr-15 12:10 
AnswerRe: Setting Textbox value using JQuery Pin
Richard Deeming2-Apr-15 2:23
mveRichard Deeming2-Apr-15 2:23 
GeneralRe: Setting Textbox value using JQuery Pin
indian1432-Apr-15 7:27
indian1432-Apr-15 7:27 
AnswerRe: Setting Textbox value using JQuery Pin
jkirkerx3-Apr-15 7:16
professionaljkirkerx3-Apr-15 7:16 
QuestionHow create a cross domain web api? Pin
miss7861-Apr-15 3:49
miss7861-Apr-15 3:49 
I am trying to create cross domain web api, however I am still unable to call data from web api url, in my ajax function. I am currently experiencing the following syntax error, under the networks, response tag.

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

The ’/ api/stw’ is currently being reported as 405 error, however when I call - http://apitesting.domain.com/api/stw, I am able to see the data is JSON format. So, I am little unsure, why is it failing in the ajax function.
HTML
$(document).ready(function () {
       $.support.cors = true;
       $.ajax({
           type: "GET",
           crossDomain: true,
           contentType: "application/json; charset=utf-8",
        //  url: "/api/stw",
            url: "<a href="http://apitesting.domain.com/api/stw">http://apitesting.domain.com/api/stw</a>,",
           data: "{}",
           dataType: "json",
           success: function (data) {
               console.log(data);
              // var myData = JSON.parse(data)
               for (var i = 0; i < data.length; i++) {
                   $("#tbDetails").append("<tr><td>" + data[i].Name + "</td><td>" + data[i].loan + "</td><td>" + data[i].evnt + "</td></tr>");
               }
           },
           error: function (result) {
               alert("Error");
           }
       });
   });

I am currently hosting my cross domain web api on the above url. I have added the custom headers in the web.config file of my web api. I have also added ‘enabled.cors’ property in my stwAPIController. I tried parsing the data in ajax through the following method ‘JSON.parse(data)’,but I am still getting the same error, as mentioned above.
C#
 [EnableCors(origins: "http://apitesting.domain.com/api/stw", headers: "*", methods: "*")]
    public class STWController : ApiController
    {
        private cdwEntities db = new cdwEntities();

<pre>
    public IEnumerable<Loan> getData()
    {

        var data = db.Database_CRE_LoanEvents.Where(c => c.Date.Contains("2015") && c.Loan_property != null)
                      .Select(x => new Loan() { Name = x.Deal, loan = x.Loan_property, evnt = x.Event })
                      .ToList().Take(3);
        return data;
    }
}</pre>

Any further help, would be very much appreciated.
AnswerRe: How create a cross domain web api? Pin
Afzaal Ahmad Zeeshan2-Apr-15 1:35
professionalAfzaal Ahmad Zeeshan2-Apr-15 1:35 
AnswerRe: How create a cross domain web api? Pin
jkirkerx3-Apr-15 7:30
professionaljkirkerx3-Apr-15 7:30 
QuestionAbsolutely lost with starting asp.net mvc Pin
Frygreen31-Mar-15 23:20
Frygreen31-Mar-15 23:20 
AnswerRe: Absolutely lost with starting asp.net mvc Pin
King Fisher1-Apr-15 0:18
professionalKing Fisher1-Apr-15 0:18 
GeneralRe: Absolutely lost with starting asp.net mvc Pin
Afzaal Ahmad Zeeshan1-Apr-15 1:14
professionalAfzaal Ahmad Zeeshan1-Apr-15 1:14 
GeneralRe: Absolutely lost with starting asp.net mvc Pin
King Fisher1-Apr-15 1:19
professionalKing Fisher1-Apr-15 1:19 
AnswerRe: Absolutely lost with starting asp.net mvc Pin
Afzaal Ahmad Zeeshan1-Apr-15 1:59
professionalAfzaal Ahmad Zeeshan1-Apr-15 1:59 
GeneralRe: Absolutely lost with starting asp.net mvc Pin
Frygreen2-Apr-15 3:45
Frygreen2-Apr-15 3:45 
GeneralRe: Absolutely lost with starting asp.net mvc Pin
King Fisher2-Apr-15 5:01
professionalKing Fisher2-Apr-15 5:01 
AnswerRe: Absolutely lost with starting asp.net mvc Pin
Afzaal Ahmad Zeeshan1-Apr-15 1:13
professionalAfzaal Ahmad Zeeshan1-Apr-15 1:13 
AnswerRe: Absolutely lost with starting asp.net mvc Pin
RajeeshMenoth1-Apr-15 1:16
professionalRajeeshMenoth1-Apr-15 1:16 
GeneralRe: Absolutely lost with starting asp.net mvc Pin
Frygreen1-Apr-15 3:02
Frygreen1-Apr-15 3:02 
GeneralRe: Absolutely lost with starting asp.net mvc Pin
jkirkerx1-Apr-15 8:10
professionaljkirkerx1-Apr-15 8:10 
QuestionChance Textmode Date Format Pin
Praveen Kandari31-Mar-15 22:34
Praveen Kandari31-Mar-15 22:34 
GeneralRe: Chance Textmode Date Format Pin
King Fisher1-Apr-15 0:15
professionalKing Fisher1-Apr-15 0:15 
GeneralRe: Chance Textmode Date Format Pin
Praveen Kandari1-Apr-15 0:24
Praveen Kandari1-Apr-15 0:24 
GeneralRe: Chance Textmode Date Format Pin
King Fisher1-Apr-15 0:31
professionalKing Fisher1-Apr-15 0:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.