0

I have this form:

<form action="#" method="post" id="cen" runat="server">
        <table>
            <thead>
                <tr>
                    <th>Contacto</th>
                    <th>Fecha</th>
                    <th>Hora</th>
                    <th >Mensaje</th>
                </tr>
            </thead>
            <tbody>
                <tr>                        
                    <td><input name="user[]" id="correo" type="email" placeholder="[email protected]" style="width: 10em;"></td>
                    <td><input name="date[]" id="fecha" type="date" data-role="datebox" data-options='{"mode": "calbox"}'></td>
                    <td><input name="hour[]" id="hora" type="text" data-role="datebox" data-options='{"mode": "timebox", "overrideTimeFormat": 12}'></td>
                    <td><textarea name="mensaje[]" id="mensaje" placeholder="Su mensaje Aqui" style="width: 15em; max-width: 15em;"></textarea></td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <td><input type="submit" value="Enviar" /></td>
                </tr>
            </tfoot>
        </table>
    </form>

I have a button to clone that form, so the user can send an array of elements.

My question: how do I send that array to a Web service with JQuery? I have this for the moment:

<script>
        $("form").submit(function (event) {
            event.preventDefault();

            var result = new XMLHttpRequest;
            var URL = "checkMessage.ashx?sendTo=" + $('#correo').val() + "&dateIn=" + $('#fecha').val() + "&hourIn=" + $('#hora').val() + "&messageIn=" + $('#mensaje');
            result.open("GET", URL, false);
            result.send;
            var resultString = JSON.parse(result.responseText);
           // var resultString = JSON.parse(result.responseText);

            if (resultString.respuesta == 1)
            {
                alert("Su mensaje fue enviado");
            }
        })
    </script>

But the web service doesn't receive anything.

For the moment in my web service I just have these:

 public void ProcessRequest (HttpContext context) {

    string[] destinatario;
    string respuesta;
    respuesta = context.Request.QueryString["sendTo"];}

Because I making test.

This is the first time I'm working with web service.

My problem is, that I can't consume the web service, and I don't know wy

2 Answers 2

1

As you are using jQuery anyway, why would you write your own ajax function, when jQuery has an excellent cross browser $.ajax function ?

$("form").on('submit', function(e) {
    e.preventDefault();

    $.ajax({
        url : 'checkMessage.ashx',
        data: {
            sendTo: $('#correo').val(),
            dateIn: $('#fecha').val(),
            hourIn: $('#hora').val(),
            messageIn: $('#mensaje').val()
        }
    }).done(function(data) {
        console.log(data);
    });
});

I'm guessing your webserver is set up to receive GET requests, and use the data your sending, and as you haven't included any code for that, it's impossible to answer ?

Also note that on the last parameter "&messageIn=" + $('#mensaje'); you're trying to send a DOM element, and that wont work.

Sign up to request clarification or add additional context in comments.

1 Comment

I alredy edit the question... Why don't gonna work? I having troubles with all these, this is the first time I'm working with all these
0

To send it to a webservice, you should use POST instead of GET.

1 Comment

But, how I send the array? Because my problem is that, I don't know how to send the array to the Web Service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.