views:

392

answers:

2

I have simple registration form. Once all information entered, user click submit button and all information sent to default.cs.asp?Process=Add2Member. Everything works. Now, I am trying to implement it into ajax Jquery so that user will stay on same page. I looked at sample codes to do this. I am confused at one point. As I understand, with ajax, I will need to grab data as QueryString but I dont want that. How can I grab it as Request.Form again.

    $("[name='signup']").click(function() { 
            $.ajax({
                type: "GET",
    url: "default.cs.asp", 
    success: function(output) { 
                $("#SIGNUPFORM").html(output); 
    //$("#SIGNUPFORM").html(output).append("Üyeliğiniz başarıyla gerçekleşti. Lütfen emailinizi kontrol edin."); 
             },
    error: function(output) {
     $(".SIGNUPFORM").html(output);
    }
    //success: function(msg, textStatus){
    //alert( "Server Response: " + msg );
    //}
            });

edit: I made a mistake with type: field. Its GET, not POST.

A: 

First of all, you have two success methods, and you can only have one. Second, you need to post your data like data:{firstName:firstname',lastName:'lastname'}, etc. Since your request is a post you should be able to use request.forms again. I assume you're using an http handler?

Chris Westbrook
I am so sorry, type not POST its GET. When I used POST, I could not retrieve server response but GET worked. But then GET is not working with Request.Form
Efe
A: 

Make the 'type' field 'POST'

Noon Silk
When its post, code does not retrieve server responses?
Efe
What do you mean? It's up to you, in your ajax callback, as to how to deal with the server response. jQuery will abstract it away so they function the same. POST is what you want to answer your question; you may have another issue in your server-code.
Noon Silk
Right, Request.Form is the correct way to access posted data. I suspect there was some error in the server code when writing the response. What response are you trying to write, and how? Try checking the status of the request in your callback function as well.
Noon Silk
Instead of '$("#SIGNUPFORM").html(output);' write 'alert(output);'. What does it say?
Noon Silk
empty alert box.
Efe
Right. Okay, so change it so that it is 'function(output, textStatus) { alert(textStatus); }. The problem is, for some reason, your server code is returning nothing.
Noon Silk
But it does return error messages when jquery not used in between. I tried textstatus, success.
Efe
Alright. I think it's the way you're building up your variables for posting then. try form.serialize() instead.
Noon Silk
any samples similar to what I will need? By the way, thank you so much for spending this much time on this.
Efe
Should be: "data : $('form').serialize()"
Noon Silk
so: $("#SIGNUPFORM").serialize();
Noon Silk
and type: "POST"? that simple??
Efe
yep. hopefully.
Noon Silk
$("#SIGNUPFORM").serialize(); gives the following error: missing } after property list Source Code: data: $("#SIGNUPFORM").serialize();, ... $("#SIGNUPFORM").serialize() gives no error but no response either.
Efe
It should work mate. At this point I'd take a step back and look for a possibly very simple problem. Sorry I can't help further.
Noon Silk
Again, thank you.
Efe
No worries, and sorry I couldn't be of more help.
Noon Silk