Testing/Building MSDN article “JSON with Padding (AJAX) ”

后端 未结 1 1758
没有蜡笔的小新
没有蜡笔的小新 2021-01-23 05:06

UPDATE 3

var local = \'http://localhost:1163/CustomerService.svc/getcustomer?method=?\';
            var dev = \'http://yourserver.com/CustomerService.svc/GetCus         


        
1条回答
  •  [愿得一人]
    2021-01-23 05:45

    In the provided sample application (JSONP) the service method is called GetCustomer and not GetLocation. So to call it:

    http://localhost:1163/service.svc/getcustomer?method=jsoncallback
    

    which returned the following response in my browser:

    jsoncallback( {"Address":"1 Example Way","Name":"Bob"} );
    

    The reason that Visual Studio Intellisense underlines the is because this is a custom binding element and not part of the schema and it is not known. You can safely ignore this warning.

    The only problem with this sample is that the files are packaged in a Class Library instead of Web Application. In order to run the service more easily in the Visual Studio built in server you could create a new Web Application, copy all the files to this new application and run it. You just need to modify this line in web.config:

    
                                                                ^
    

    to include your web application name:

    
                                                                  ^
    

    That's all. Now go ahead and write a client application which consumes this JSONP stream. jquery does a great job with the $.getJSON() method:

    $.getJSON('http://localhost:1163/service.svc/getcustomer?method=?', function(customer) {
        alert(customer.Address); 
    });
    

    I have uploaded my working version here.

    0 讨论(0)
提交回复
热议问题