asp.net - Can not get proper value in javascript from web service -


here problem: have web service method returns simple string:

namespace webstockservice {     [webservice(namespace = "http://tempuri.org/")]     [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]     // allow web service called script,      // using asp.net ajax, uncomment following line.      [system.web.script.services.scriptservice]     public class stockservice : system.web.services.webservice     {         [webmethod]         public string getchallenge()         {             //some codes             return string;         }     } 

i want call service in javascript:

try {    var challenge = webstockservice.stockservice.getchallenge(); } catch(e) {    alert(e.messsage); } 

i have not got error message in call, when debug script challenge undefined!!!

i have tested web service method in asmx fashion , invokes , returns string.

i have inserted scriptmanager tag in html:

<asp:scriptmanager id="webstockservice" runat="server">             <services>                 <asp:servicereference path="stockservice.asmx" />                            </services> </asp:scriptmanager>  

any appreciated.

this line must changed

var challenge = webstockservice.stockservice.getchallenge();

please try following

webstockservice.stockservice.getchallenge(successcallback);  function successcallback(returnedstring) {   alert(returnedstring); } 

you must pass callback javascript function execute. call webservice asynchronous in nature , won't intended behavior tried in code. reading ajax give better idea. detailed answer here


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -