views:

124

answers:

2

Hi, I want to send three text box values to server using jquery ajax. problem is that, i dont know the exact syntax to send three data. When i try sending one data(also change no.of parameters to one at server side method), its going good but when i try to send three text box values, its giving jquery error:"Internal server error". I think I am not sending data in correct way. please somebody tell me how to do that.

Below is the code:

function testCAll() {
$.ajax({
    type: "POST",
    url: "dbTest1.aspx/SendMessage",
    data: "{'name': '" + $('#Eid').val() + "', 'phone': '" + $('#phn').val() + "'}",
    //data: "{'phone': '" + $('#CustomerPhone').val() + "'}",
    //data: "{'color': '" + $('#ColorId').val() + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(result) {
        resultData = eval("(" + result.d + ")");
        $("#rawResponse").html(concatObject(resultData));
    },
    error: function(result) {
        alert("jQuery Error:" + result.statusText);
    }
});

}

+1  A: 

instead of how you encode data now, try doing this:

data: {'name':  $('#Eid').val(), 'phone': $('#phn').val() }
mkoryak
thanks but problem is still there
amby
A: 

If you're dealing with input fields within a form, you should give those input's a 'name' attribute and use

var dataarr = $('#formid').serializeArray();

and within your .ajax() function:

data: JSON.parse(dataarr);

and by the way, you don't have to use eval() if you're using jQuery v.1.4.x with dataType = 'json'. Otherwise, JSON.parse() should be used to create a js object.

Kind Regards

--Andy

jAndy