Sending dynamic data through JQuery Ajax
Hi All,
I've got a question about the processing of data through and Ajax Post Request which i can't get a hold of. Hopefully you guys can help me out.
I have the following situation.
An anchor is my script triggers the following javascript function:
- <a href="#fragment-3" onclick="return drawResource();"><span>Resources</span></a>
I have the following function
- function drawResource(url) {
$.ajax({url: "resource.asp",
type: "POST",
dataType: "html",
cache: false,
data: {period:201209},
success: function(responseData) {
alert(responseData);
}
});
}
The requested asp file looks like this.
- <%
dim z
z = Request.Form("period")
response.write "z = " & z
%>
Until this this works fine. My next step is to make the "data: {period:201209}," dynamic. So i tried testing it like this:
- function drawResource(url) {
datatosend = "{period:201209}";
$.ajax({url: "resource.asp",
type: "POST",
dataType: "html",
cache: false,
data: datatosend,
success: function(responseData) {
alert(responseData);
}
});
}
which fails....
I i ran i trough Firebug i see a remarkable difference.
in the first case i see this:

and in the 2nd case i see this:

Looks like in the 2nd case my variable datatosend is interpretated as JSON data to send, while in the 1st case it comes over as a String. Is there anyone that can help me out getting the 2nd option to work?
Edit:
in the 1st case response is z = 201209 in the second case response is z =