Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you have given the tags as jQuery and jQuery Ajax I am deviating a little from the solution.</p> <p>Do these things</p> <p>1.Wrap your <code>WebMethod</code> in a try-catch block. try-catch are there for a reason. </p> <pre><code>[WebMethod] public static string GetDataFromDB() { try { System.Collections.Generic.Dictionary&lt;string, string&gt; DictionaryGetPerson = new Dictionary&lt;string, string&gt;(); using (OracleConnection con = new OracleConnection("server=xe; uid=system; pwd=;")) { string Command = "Select * from tblSavePerson"; //selecting Top 1 Row in Oracle OracleCommand cmd = new OracleCommand(Command, con); con.Open(); OracleDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { DictionaryGetPerson.Add("FirstName", dr["FirstName"].ToString()); } } JavaScriptSerializer js = new JavaScriptSerializer(); return js.Serialize(DictionaryGetPerson).ToString(); } catch (Exception exception) { //Elmah.ErrorSignal.FromCurrentContext().Raise(exception); throw new Exception(exception.Message); } } </code></pre> <p>Please note that this Dictionary will fail with Duplicate Key error if you have more than one row. If there are no errors lets move to step 2.</p> <p>2.Do not use <strike><code>PageMethods.GetDataFromDB</code></strike>. It very <em>ancient</em>. <a href="http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/" rel="nofollow">Using jQuery one can consume ASP.NET Ajax Page Methods directly</a>. Call Page method like this.</p> <pre><code>function LoadNames() { $.ajax({ contentType: "application/json;", data: "{}", type: "POST", url: 'Test1.aspx/GetDataFromDB', success: function (msg) { OnSucceeded(msg); }, error: function (xhr, status, error) { //alert("error"); //OnFailed(a, b, c); } }); } function OnSucceeded(dict) { var jsonData = dict.hasOwnProperty("d") ? dict.d : dict; var json = $.parseJSON(jsonData); alert(json.FirstName); } </code></pre> <p>Also, don't <strike><code>eval(result.d)</code></strike> when we have <code>$.parseJSON</code> in jQuery.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload