Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me find the mistake i cant find it

this code is in my master page (.master)

XML
<script type="text/javascript">
      var txtsearch = $("#<%=txtSearch.ClientID%>");
      $(document).ready(function () {

          $("#<%=txtSearch.ClientID%>").keyup(function (e) {



              var option = {
                  type: "POST",
                  url: "searchsmall.aspx/SmSearch", 
                  data:"{}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function (msg) {
                      alert(msg);
                  }
              };

              $.ajax(options);
          })



      })


  </script>



and (.cs) file


C#
using System.Web.Services;

namespace CellPhone
{
    public partial class searchsmall : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        public static string SmSearch()
        {

            return "hiii";
        }
    }
}


the error is 'option' is undefined

nothing happen when i am typing please help.
Posted
Updated 21-Dec-11 7:44am
v2
Comments
thatraja 21-Dec-11 13:06pm    
What's the error? check it
Christ_88 21-Dec-11 13:10pm    
i fact i dont know how can i check it in VS 2010
Parwej Ahamad 21-Dec-11 13:27pm    
Verify browser developer tool console what is the cause of error then post here that line.
Christ_88 21-Dec-11 13:41pm    
the error is 'option' is undefined

You first need to learn how to find the error that is occuring by learning how to use the debugger in Visual Studio. (These[^] might help with that).

It might help if you add the "error(jqXHR, textStatus, errorThrown)" component to your jquery call with an alert to display if an error is occuring.
 
Share this answer
 
Comments
Christ_88 21-Dec-11 13:41pm    
really thank you
thatraja 21-Dec-11 13:50pm    
Nice suggestion Pogoboy, 5!
I think the issue can with your client id OR option variable. So let try both. if you are using framework4.0 then try to set text box property as ClientIDMode='Static' and use direct textbox id instead of id.
like: $("#yourtextboxid")

Second observation with your option variable try to use direct Ajax call like:

JavaScript
<script type="text/javascript">
      var txtsearch = $("#<%=txtSearch.ClientID%>");
      $(document).ready(function () {
 
          $("#<%=txtSearch.ClientID%>").keyup(function (e) {
 

 
              var option = $.ajax({
                  type: "POST",
                  url: "searchsmall.aspx/SmSearch", 
                  data:"{}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function (msg) {
                      alert(msg);
                  }
              });
          });
      });
 

  </script>


Let me know if still not working
 
Share this answer
 
Comments
thatraja 21-Dec-11 13:50pm    
Possible case, 5!
Parwej Ahamad 21-Dec-11 13:52pm    
Thanks :)
Christ_88 21-Dec-11 13:56pm    
but the alert message is [object Object] where is the problem ?
Parwej Ahamad 21-Dec-11 14:03pm    
Not an issue, now started getting object so just use msg.d

Please refer this URL for complete example:
http://brian.dobberteen.com/code/calling-a-pagemethod-with-jquery/
Parwej Ahamad 21-Dec-11 14:00pm    
Not an issue, now started getting object so just use msg.d
really sorry for this post the mistake was very very funny

$.ajax(options);

should change to

$.ajax(option);
 
Share this answer
 
Comments
thatraja 21-Dec-11 14:07pm    
Its OK, Glad you have solved the issue yourself, Take a 5!
fjdiewornncalwe 21-Dec-11 14:16pm    
Thanks for sharing the fix.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900