Amby,
I think you will stand more chance by moving $('#result').html.... inside the success handler and JSON decode it, like this :
String.prototype.parseJSON = JSON.decode;//make sure you have the JSON lib loaded.
$(document).ready(function() {
$("button").ajaxStart(function() {
alert('Triggered ajaxStart handler.');
});
$("button").click(function() {
$.ajax({
type: "POST",
dataType: 'JSON',
url: "Testing.aspx/SendMessage",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
success: function(result, txtStatus, httpRequest) {
$('#result').html(concatObject(httpRequest.responseText.decode()));
}
});
});
});
This may not be 100% correct yet but should be a step in the right direction.
And concatObject would be less memory hungry if it were written :
function concatObject(obj) {
strArray = [];//new Array
for (prop in obj) {
strArray.push(prop + " value :" + obj[prop]);
}
return strArray.join("\n");
}
Successive string concatenations using += are inefficient because at each concatenation, a complete new string has to be created and returned. Meanwhile, an increasing number of discarded component strings accumulates in memory waiting to be cleaned up by javascript's automatic garbage collection at some unknown point in the future. In Javascript the array.push ... array.join approach is efficient because not only does it overcome the inherent memory hungriness but also, Javascript arrays are very cheap (low overherad).Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Amby,
I think this script seems to be working in that the displayed response toJSON value :function (key) { return this.valueOf(); }
is of the right format for something processed by your concatOnject function.
Two things to try :The jQuery API says to use dataType: 'json' , rather than dataType: 'JSON', . Probably no difference but worth a try.
Use the following code to look at the raw, undecoded response to see if it is what you expect :
$.ajax({
type: "POST",
//dataType: 'JSON',
url: "Testing.aspx/SendMessage",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
success: function(result, txtStatus, httpRequest) {
alert(txtStatus);
$('#status').html(result);
}
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Amby,
From what you say, it seems that your problem is server-side. The server appears not to be running the .aspx script. If you have other .aspx pages that run correctly, then the most likely thing is that the file extension is incorrect. Otherwise, check that the server is configured to run .aspx and that the script contained therein is of the correctly formed (see this for example).
To test the script, try running it directly by typing its URL into the browser's address bar rather than having it as an AJAX call. That will remove one level of uncertainty.
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Amby,
"Hello world" not coming through worries me.
Try making a very simple "test.aspx" test script that serves "Hello world" with everything else deleted. See what comes back.
If it still fails, try changing the file name to "test.html" and see if the response is any different.
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372