none
Consuming JSONP service from HTML5 page RRS feed

  • Question

  •  Hi,

    i have taken JSONP sample from http://msdn.microsoft.com/en-us/library/bb410770(v=vs.110).aspx
    \WF_WCF_Samples\WCF\Basic\Ajax\JSONP\CS here the service is consumed in aspx page. 

    i just want to access the service from my HTML page. 1) is it possible?

    2)in an attempt to consume WCF service returning JSONP , i tried with the instruction provided here:http://msdn.microsoft.com/en-us/library/ee834511(v=vs.110).aspx

    3)my try:please let me know how can i achieve it.

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>My Website</title>
    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript" >
    function makeCall() {
                    var proxy = new JsonpAjaxService.CustomerService();
                    proxy.set_enableJsonp(true);
            proxy.GetCustomer(onSuccess, onFail, null);
            }
            // This function is called when the result from the service call is received
            function onSuccess(result) {
                    document.getElementById("name").value = result.Name;
                    document.getElementById("address").value = result.Address;
            }
            // This function is called if the service call fails
            function onFail(){
            document.getElementById("name").value = "Error";
            document.getElementById("address").value = "Error";
            }
    $(document).ready(function(){
    $("#getDataBtn").on("click", function(){
    makecall();
    script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://localhost:33695/service.svc?jcallback=GetCustomer";
    alert(script.innerText);
    /*$.ajax({
    url:"http://localhost:10637/RestServiceImpl.svc/json/1",
    dataType:"jsonp",
    type:"POST",
    contentType:"Application/jsonp",
    crossDomain:true,
    success:function(data){
    alert(data);
    },
    error:function(){
    alert("error");
    }
    });
    });
    </script>


    </head>
    <body>
    <input type="button" value="Get Data" id="getDataBtn"/>
    <h1>
            JSONP Service Client Page</h1>
            Customer:
            <p/>
            Name: <input type="text" id="name"/>
            <p/>
            Address: <input type="text" id="address"/>
            
    </body>
    </html>

    Friday, January 17, 2014 5:21 AM

All replies

  • Hi,

    I'm afraid that it is not the correct forum about this issue, since this forum is to discuss WPF.

    So I have moved this thread to WCF forum for better response.

    Thanks for your understanding.

    Best regards,
    Franklin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 20, 2014 2:44 AM
  • Hi Franklin,

    Thanks for moving it to appropriate forum. by mistake i put it in WPF forum just tracing my previous activity. As most of my work is on WPF. but even after you moved it, Are there no takers? :( .

    i am trying reference available http://blogs.microsoft.co.il/idof/2011/07/02/cross-origin-resource-sharing-cors-and-wcf/.

    lets see if i get some help!!

    Regards,

    Kamlendra

    Thursday, January 23, 2014 12:03 PM