views:

46

answers:

2

Hi there.

I want to post data to a web service with ajax. there is my ajax code:

 function Looping() {
        var Grid = document.getElementById("<%= gvHastalar.ClientID %>");
        var Row;
        var Cell;
        if (Grid.rows.length > 2) {
            for (i = 1; i < Grid.rows.length - 1; i++) {
                Row = Grid.rows[i];
                Cell = Row.cells[3];
                alert(Cell.innerHTML);
                var html = $.ajax(
                {
                    type: "POST",
                    url: "http://localhost:7753/HastaTahlilUyariServisi.asmx/f_HastaninAktarilacakAlislabTestleri",
                    data: "{_sTcKimlikNo:" + Cell.innerHTML + ",_iKlinikKodu:18001,_bAy:12,_iYil:2009}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: alert('success'),
                    error: alert('error')
                }
                ).responseText;
                Row.style.backgroundColor = "#D3EFD1";
            }
        }
    }

And my webservice function's code is here:

 [WebMethod]
    [SoapHeader("_ticket", Direction = SoapHeaderDirection.In)]//SoapHeaderDirection.Out
    public DataSet f_HastaninAlisLabTahlilleri(string _sTcKimlikNo, int _iKlinikKodu, byte _bAy, int _iYil)
    {
        try
        {
            string QSelect =
                               @"SELECT * FROM [V_EUCLID_SONUC]
                                 WHERE  MONTH(KAYITTARIHI) = " + _bAy + @"
                                   AND YEAR(KAYITTARIHI) = " + _iYil +
                                   AND TCKIMLIKNO = '" + _sTcKimlikNo + @"'";

            return dbA.ExecuteDataSet(CommandType.Text, QSelect);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }

There is a break point on function which is in the web service but debug never go that break point. I pasted webservice's url from browser but may be url is wrong. And when i run project, i have 3 alert. First Cell's text its normal.Second alert is success and the last alert is error. I want to send parameters to f_HastaninAlisLabTahlilleri and user return dataset. How can i do this?

Thanks in advance

A: 

You cannot put a break-point in the web-service code i.e. even the IDE would not let u debug the web-service code.... it is an old legacy the VS.Net IDE has since its inception... lets see if it is resolved in VS 2010.

HotTester
What? Untrue. For instructions, see http://msdn.microsoft.com/en-us/library/0twaftwz.aspx.
Jeff Sternal
+1  A: 

Here are a few remarks about your code:

  1. success and error are callback functions, they should be defined like this:

    success: function(data) { alert('success'); },
    error: function(XMLHttpRequest, textStatus, errorThrown) { alert('error'); }
    
  2. ASMX web services use SOAP by default unless you decorate them with ScriptServiceAttribute in which case JSON could be used to invoke a method. It is not clear from your code if the web service is decorated with this attribute.
  3. When you pass parameters, you need to encode them, use JSON. stringify instead of concatenating strings:

    data: JSON.stringify({_sTcKimlikNo: Cell.innerHTML, 
                          _iKlinikKodu: 18001,
                          _bAy: 12,_iYil: 2009});
    

Use FireBug to inspect network AJAX requests and server responses and post them on StackOverflow to facilitate debugging.

Darin Dimitrov