Click here to Skip to main content
15,665,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

i have this sample code in jQuery that connect to my WebService

sending text, and receive text. its works excellent.

<html  lang="en-US">
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
        <meta name="viewport" content="width=device-width" />
        <script type="text/javascript" src=""></script>
        <script type="text/javascript">

            //var WS_URI = '';
            var WS_URI = '';
            var MAKAT ;

            function Look() {
                MAKAT = document.getElementById("txt").value.toString();
                    ServiceCallID: 1,
                    url: WS_URI,
                    type: 'POST',
                    data: '{"Makat": "' + MAKAT + '"}',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                        function (data, textStatus, XMLHttpRequest) {
                  function (XMLHttpRequest, textStatus, errorThrown) {

<body >
          <br />
          <button onclick="Look();">Press me</button>
          <input id="txt"  value="1111"/>
          <br />
          <p id="RES">res</p>

now i need to receive DataSet (xml),

i build WebService (in C#) that receive text and sending DataSet

but the jQuery dosent work.

I broke my head for two days and can not seem to find a solution....

On Service side pls check
1. u have to add

before web service class to enable service access from script
2. add this before web service method
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]

to specify the out put format
3. better return Data as xml instead of DataSet

On Client side

         url: WS_URI,
         type: 'POST',
         data: "Makat="+ MAKAT,
         dataType: "xml",
           function (data) {
             var item=$(data).find('Item').text();
             var des=$(data).find('Des').text();
           function (errorThrown) {
Share this answer
goldsoft 18-Jul-14 6:45am    
thanks !!!!!! its work !!!!!!!
change datatype as
dataType: "xml",
Share this answer
goldsoft 18-Jul-14 3:17am    
thanks for the help, i try this but i got error.
my WebService code:
public DataSet GetItem(string Makat)
dsView = new DataSet();
SQL = "select Item,Des from MyTbl where Item = '" + Makat + "'";
dsView = new DataSet();
adp_SQL = new SqlDataAdapter(SQL, Conn_SQL);
adp_SQL.Fill(dsView, "MyTbl ");
if (dsView.Tables["MyTbl "].Rows.Count >= 1)
return dsView;
return null;
goldsoft 18-Jul-14 3:41am    
i try this:

contentType: "text/xml",
dataType: "text",

and got this error:

POST 500 (Internal Server Error) jquery.min.js:130
c.extend.ajax jquery.min.js:130
Look (index):14

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