Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Monday, May 27, 2013

Jquery Ajax post Custom Object as Json to Wcf Service


function LoadMore() {

    var myData =
    {
        arguments : {
            Category: "Main",
            SearchText: "",
        }
    };


    var jsonedArguments = JSON.stringify(myData);

    $.ajax({
        type: "POST",
        url: "/PublicService.svc/LoadMore",
        contentType: "application/json; charset=utf-8",
        cache: false,
        data: jsonedArguments,
        dataType: "json",
        processdata: true,
        success: function (data) {
         
            debugger;
            var xx = data;

        },
        error: function (msg) {
            alert('CallFiles failed!!!!');
        }
    });
}



 [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public GetFilesResult LoadMore(GetFilesArguments arguments)
        {
            return new GetFilesResult() { TotalCount = 100 };
        }

Thursday, May 2, 2013

jquery ajax enabled wcf Service call sample



    <script language="javascript" type="text/javascript">

        $(function () {
            CallSiblingMenu();
        });

        function getUrlParts(url) {
            var a = document.createElement('a');
            a.href = url;

            return {
                href: a.href,
                host: a.host,
                hostname: a.hostname,
                port: a.port,
                pathname: a.pathname,
                protocol: a.protocol,
                hash: a.hash,
                search: a.search
            };
        }

        function getNavigationUrl()
        {
            var url = window.location.href;
            var navigationUrl = getUrlParts(url).pathname;
            return navigationUrl;
        }

     

        function CallSiblingMenu() {

            var relativeUrl = getNavigationUrl();
            var baseControl = "#siblingsMenu";
            var html = '';

            //clear
            $(baseControl).html('');

            //add loading
            html = html + '<div id="loading" style="margin-left:50px;margin-top:50px;">';
            html = html + '<img src="/App_Themes/Common/Images/loading.gif"  /></div>';
            $(baseControl).append(html);

            $.ajax({
                type: "POST",
                url: "/PublicService.svc/GetSiblings",
                data: '{"relativeUrl": "' + relativeUrl + '"}',
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                processdata: true,
                success: function (data) {
                   
                    //remove loading
                    $('#loading').remove();

                    $.each(data.d, function (i, item) {

                        $(baseControl).append('<a class="" href="' + item.Url + '" ><div>' + item.Title + '</div></a>');
                    });

                },
                error: function (msg) {
                    $(baseControl).html('');

                    alert('CallSiblingMenu failed!!!!');
                }
            });
        }



    </script>



</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="LeftNavigationContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div id="dynamic-wrapper">
        <div id="siblingsMenu"></div>

        <div id="content" runat="server" clientidmode="static">
        </div>

        <div class="clearfix"></div>

    </div>
</asp:Content>

Wednesday, May 1, 2013

Parse WCF Service Date with Javascript


function ToShortDate(dateAsFromServerSide) {

    var parsedDate = new Date(parseInt(dateAsFromServerSide.substr(6)));

    var jsDate = new Date(parsedDate); //Date object
    var day = jsDate.getDate() < 10 ? '0' + jsDate.getDate() : jsDate.getDate();
    var month = jsDate.getMonth() < 10 ? '0' + jsDate.getMonth() : jsDate.getMonth();
    var year = jsDate.getFullYear();

    var result = day + '.' + month + '.' + year

    return result;
}

Wednesday, February 27, 2013

Telerik RadWindow Set Behaviors Client Side



//this is radbutton onclientclicking event
function openWindow(sender, args) {
 
    //create window
    var parentPage = GetRadWindow().BrowserWindow;

    //open window
    var win = parentPage.radopen("url_here, null);

    //set properties
    win.setSize(400, 600);
    win.setTitle("ActionLogs Window");
    win.setActive();
    win.setModal(true);

//set behaviors
    win.set_behaviors(winBehaviours.Close | winBehaviours.Move);

    //prevent postback
    args.set_cancel(true);

}


var winBehaviours = {

    None: 0,
    Resize: 1,
    Minimize: 2,
    Close: 4,
    Pin: 8,
    Maximize: 16,
    Move: 32,
    Reload: 64
}


function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement && window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
}



Tuesday, July 3, 2012

Javascript Page Document ready, PageLoad, Application Init


$(document).ready()
  • Ideal for onetime initialization.
  • Optimization black magic; may run slightly earlier than pageLoad().
  • Does not re-attach functionality to elements affected by partial postbacks.
pageLoad()
  • Unsuitable for onetime initialization if used with UpdatePanels.
  • Slightly less optimized in some browsers, but consistent.
  • Perfect for re-attaching functionality to elements within UpdatePanels.
Application.Init
  • Useful for onetime initialization if only ASP.NET AJAX is available.
  • More work required to wire the event up.
  • Exposes you to the “sys is undefined” error if you aren’t careful.

Monday, July 2, 2012

jquery no transport


Jquery Code

<script type="text/javascript">

             var menuUrl = "http://localhost:3648/PublicService.svc/MenuList";

             function caller() {
                 $.support.cors = true;
                 $.ajax({
                     cache: false,
                     type: "POST",
                     async: false,
                     dataType: "json",
                     url: menuUrl,
                     success: function (data) {
                         debugger;
                         $("#containerDiv").html(data);
                     },
                     error: function (xhr) {
                         debugger;
                         alert(xhr.responseText);
                     }

                 });
             }

             $(document).ready(function () {
                 debugger;
                 caller();
             });
       
    </script>


SYMPTON: Message:No Transport Code:0
REASON: You're trying to make cross-domain request

SOLUTION: $.support.cors = true;



Tuesday, May 22, 2012

javascript window.location is not working properly in safari, chrome and firefox.


Command must be used like window.location = 'url address' instead of window.location('url address')


shortly use this: window.location = 'url address'