-
Javascript not working (ajax with asp)
Hello, I seem to have a rather strange error.
JavaScript:
// JScript File
var objXMLHttp
function subscribe(str) {
var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
if (!regEx.test(str)) {
document.getElementById('div').innerHTML = 'Invalid email';
alert('Invalid email!');
return false;
}
objXMLHttp=createXmlHttpObject()
if (objXMLHttp==null) {
alert ('Your browser does not support the XMLHttpRequest object!');
return;
}
var url='subscribe.aspx?eml=' + str + '&sid=' + Math.random();
objXMLHttp.onreadystatechange = stateChanged;
objXMLHttp.open('GET',url,true); // GET method
objXMLHttp.send(null); // always use null for GET method
}
function createXmlHttpObject() {
var req = null;
try {
req = new XMLHttpRequest(); //ie7, ff, safari
}
catch (e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP"); //later ie
}
catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP") // earlier ie
}
catch (e) {
// could not create XMLHttpRequest object
return false;
}
}
}
return req;
}
function stateChanged()
{
if (objXMLHttp.readyState == 0) {
document.getElementById("div").innerHTML = "Processing..."; //uninitialized
}
else if(objXMLHttp.readyState == 1) {
document.getElementById("div").innerHTML = "Processing..."; //loading
}
else if(objXMLHttp.readyState == 2) {
document.getElementById("div").innerHTML = "Processing..."; //loaded
}
else if(objXMLHttp.readyState == 3) {
document.getElementById("div").innerHTML = "Processing..."; //interactive
}
else if (objXMLHttp.readyState == 4 || objXMLHttp.readyState == "complete") {
document.getElementById("div").innerHTML= objXMLHttp.responseText;
}
}
The file subscribe.aspx has a page_load method which just do Response.Write("Test");
I get an error when trying to get the response (objXMLHttp.responseText)
If I replace this:
document.getElementById("div").innerHTML= objXMLHttp.responseText;
with this:
document.getElementById("div").innerHTML= "Test";
It works. Anyone know why I can't get the response message that subscribe.aspx generates?
-
Hi,
Did you get the solution to this problem ? I am too having the similar problems in one of my Perl script.
Thanks
Shyam
Similar Threads
-
By Iain Munro in forum ASP.NET
Replies: 0
Last Post: 02-22-2002, 07:44 AM
-
By Botard in forum ASP.NET
Replies: 2
Last Post: 12-05-2001, 04:29 PM
-
Replies: 1
Last Post: 11-20-2001, 03:47 AM
-
Replies: 1
Last Post: 10-01-2001, 11:46 PM
-
By Charity in forum ASP.NET
Replies: 3
Last Post: 01-17-2001, 10:52 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks