jQuery and .NET 2.0
I made a .NET 2.0 Application using jQuery.
However when I deploy it on my server that doens't have .NET 3.5 installed it doesn't work.
I get no errors and have no idea how to debug it.
I use jquery-1.3.2.min.js.
Works perfect in my test environment and on my other server with 3.5 installed.
Once it is uploaded to the production server with 2.0 every callback in ASP.NET fails.
<script type="text/javascript">
$(document).ready(function() {
var item = $("[id$='txtItemName']");
var category = $("[id$='ddlCategories']");
var record = $("[id$='txtRecordID']");
$("#btnSave").click(function() {
if (item.val().length == 0) {
alert("Please enter item name first.");
return false;
}
if (category.val().length == 0) {
alert("Please select a category.");
return false;
}
var paramArray = ["testText", escape(item.val()), "categoryID", category.val(), "recordID", 1];
PageMethod("SaveMyData", paramArray, AjaxSucceeded, AjaxFailed);
});
});
function AjaxSucceeded (result)
{
alert("lykkedes" + result);
}
function AjaxFailed(result)
{
alert("failed" + result);
}
function PageMethod(fn, paramArray, successFn, errorFn) {
var pagePath = window.location.pathname;
//Create list of parameters in the form:
//{"paramName1":"paramValue1","paramName2":"paramValue2"}
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
if (paramList.length > 0) p开发者_Go百科aramList += ',';
paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
}
}
paramList = '{' + paramList + '}';
//Call the page method
$.ajax({
type: "POST",
url: "DataProcessor.aspx?" + fn + "=1",
contentType: "application/json; charset=utf-8",
data: paramList,
dataType: "json",
success: successFn,
error: errorFn
})
;}
</script>
And the DataProcessor procedure looks like this:
public void SaveMyData()
{
System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
string line = "";
line = sr.ReadToEnd();
JObject jo = JObject.Parse(line);
string temp = (string)jo["recordID"];
Response.Write(temp);
}
I enter the AjaxFailed(result) when I try it....
Any help and suggestions are much appriciated...
I am not proud to answer my own question here, because it is truely a noob mistake I made...
The JSON DLL I used was not the one with .NET 2.0 SUPPORT. I have somehow ignored the fact and it worked on my test environment with 3.5 installed.
I Downloaded the latest version of the JSON.net dll and used the 2.0 DLL and everything worked out like a charm.
Thanks for the contributions in here.
The problem may be the JSON serializer, does your server have the ASP.Net 2.0 AJAX Extensions installed?
If you can't debug, because its on the production enviroment, then are you able to insert diagnostics?
Are you hitting the AjaxFailed function, or not at all?
A first suggestion would be to write simple alert() statements at code intervals to see if you can trace what is happenening. You may want to look at the httpresult status and the httpresult responseText that is being returned from the call.
On the server side, can you write out to some log file values at specific stages, i.e. the JSON string.
Would also echo the above with regard to the serialiser. Try using
using System.Web.Script.Serialization;
JavaScriptSerializer jss = new JavaScriptSerializer();
MyCustomClass mcc = jss.Deserialize<MyCustomClass>(someJSONstring);
string someOtherJSONString = jss.Serialize(mcc);
精彩评论