mbielanczuk / jQuery.Gantt

jQuery Gantt Chart
http://mbielanczuk.com/?p=34
325 stars 461 forks source link

How to use external datasource - asp webservice #25

Open Misiu opened 12 years ago

Misiu commented 12 years ago

Hi all, I am wondering how to use external data source, but not json file, but asp webservice.

If I do this:

source: dataPath + "js/Meetings.js"

gantt is displayed correct,

but if I do this:

source: dataPath + "Meetings.asmx/GetAll" 

I get error:

[InvalidOperationException]: Format żądania jest nierozpoznany dla adresu URL nieoczekiwanie kończącego się w „/GetW”.
   w System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   w System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
   w System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
   w System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   w System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   w System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

How to correct this or any ideas how to use asp webservice result?

Misiu commented 12 years ago

Got this working. I had to change piece of code:

create: function (element) {
    if (typeof (settings.source) == 'object') {

        if (settings.source.hasOwnProperty("d")) element.data = settings.source.d;
        else element.data = settings.source;
        core.init(element);
    } else {
        $.ajax({
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: '{}',
            dataType: 'json',
            url: settings.source,
            success: function (result) {
                if (result.hasOwnProperty("d")) element.data = result.d;
                else element.data = result;
                core.init(element);
            }
        });
    }

}

Sorry for posting this here, but I don't know (for now) how to use github to post path.

I've added ajax instead of getJSON because but webservice wasn't parsed, now it is. Second change was adding check for "d" property. .NET is wrapping json result in extra d element for security reasons.

Hope this helps.