views:

62

answers:

2

I am having some trouble sending values from one page to another using the jQuery ajax() function.

For some reason the request.form on my VBscript page won't pick up the data I send using the ajax() function in jQuery.

Here is my javascript function which is called in an onsubmit event in my form:

function sendData() {
 $.ajax({
  type: "POST",
  url: "/useData.asp",
  data: {
   newData: $("form[name=myData] [name=newData]").val()
  },
  success: function(response) {
   $("#responseData").html(response);
  },
  error: function(xhr) {
   alert("Error: " + xhr.status);
  }
 });

 return false;
}

And here is my VBscript:

<%=request.form("newData")%>

For some reason when I use POST I don't get any data returned in the responseData div. But if I change POST to GET and request.form to request.queryString I get my data as I should do.

Can anybody tell me why POST and request.form are not working?

A: 

I found my problem.

We are using IIS7 and have used some of the pre-defined URL rewriting rules in the URL rewrite module.

It seems that enforcing lowercase URLs causes a lot of problems with this kind of stuff, so I deleted the lowecase URLs rule from the site in IIS7 and it works fine now.

Sour Lemon
A: 

here is a simple example of jquery and asp.net using c# (hope that work for VB.net): this example will show an alert with the message "hello my friend: Dr Dre."

we will be sending a string to a method in codebehind, as you can see in the script below, we specifie in the options varible the the name of the method that will receive the data in the codebehind (url), and the name of the arguments to process (data)

   $(document).ready(function() {
        var myname="Dr Dre."
        var options =
                    {
                        type: "POST",
                        url: "yourpage.aspx/SayHelloTo",
                        data: '{"name":"' + myname + '"}',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(response) {
                            if (response.d != "") {
                                   alert(response.d);
                            }
                        }
                    };
                    $.ajax(options);
    });

the method should be decorated by [WebMethod] and static property

[WebMethod]
public static string SayHelloTo(string name)
{
    return "hello my friend: "+name;
}

hope that will help.

aleo
Thank you for taking your time to try and help me, but I have found the answer to my problem, which was in the URL rewrite module for IIS7.
Sour Lemon