OutFront Forums
     Home    Register     Search      Help      Login    

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

 

AJAX Help - save only works sometimes

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> AJAX Help - save only works sometimes
Page: [1]
 
 
dzirkelb1

 

Posts: 1444
Joined: 10/5/2004
From: Cedar Rapids, Iowa
Status: offline

 
AJAX Help - save only works sometimes - 3/24/2009 9:32:37   
I am having issues with my AJAX page only saving about 1/2 the time on the same field. It will save a bunch in a row, then it won't save one at all with every attempt I do. Here is the ajax code:

function SaveRecordDetails(strFieldName, intPOLineID, strValue, FieldType)
{
	if(/&/.test(strValue)) {
		alert("ERROR!  You can not enter the & key.  Re-enter your entry without the & to have the data save.  Data was not saved!");	
		return false; }
	else
		var url="Receiving-Recg-save.asp?UpdateDetails=Yes&Value=" + strValue + "&FieldName=" + strFieldName + "&POLineID=" + intPOLineID + "&FieldType=" + FieldType
		alert(url)
	    xmlHttp=GetXmlHttpObject(stateChangedSaveRecord)
    	xmlHttp.open("GET", url , true)
	    xmlHttp.send(null) 
}

function stateChangedSaveRecord()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        xmlHttp.responseText
    }
}

function GetXmlHttpObject(handler)
{
    var objXmlHttp=null
 
    if (navigator.userAgent.indexOf("Opera")>=0)
    {
        alert("Opera not supported...")
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        }
        try
        {
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler
            return objXmlHttp
        }
        catch(e)
        {
            alert("Error. Scripting for ActiveX might be disabled")
            return
        }
    }
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
    }
}  



here is the url that is passed as an example:

https://ecis.deei.com/receiving-recg-save.asp?UpdateDetails=Yes&Value=0&FieldName=[SCHDQTY]&POLineID=438988&FieldType=NonText


Which outputs this as the sql query:

UPDATE PORECGS1 SET [SCHDQTY] = 0 WHERE (POLineID = 438988)


I plug in the alert of the url into another page and it saves correctly everytime. Here is the code for the other page that does the saving:

<!-- #include file="dbQS.asp" -->
<%
strPONumber = request.querystring("PONumber")
intPOLineID = request.querystring("POLineID")
strUpdateDetails = request.querystring("UpdateDetails")
strUpdateHeader = request.querystring("UpdateHeader")

strFieldName = request.querystring("FieldName")
strValue = request.querystring("Value")
strFieldType = request.querystring("FieldType")

if len (strUpdateDetails) > 0 then
	if strFieldType = "NonText" then
		if strValue = "" then
			strValue = "null"
		end if	

		ssql = "UPDATE PORECGS1 SET "&strFieldName&" = "&strValue&" WHERE (POLineID = "&intPOLineID&")"
	else
		ssql = "UPDATE PORECGS1 SET "&strFieldName&" = '"&strValue&"' WHERE (POLineID = "&intPOLineID&")"
	end if
	
	response.write(ssql)
	dbc.execute(ssql)
	
	dbc.close
	set dbc=nothing
end if

if len (UpdateHeader) > 0 then
	if strFieldType = "NonText" then
		if strValue = "" then
			strValue = "null"
		end if	

		ssql = "UPDATE [PURCHASE ORDERS] SET "&strFieldName&" = "&strValue&" WHERE ([PO NUMBER] = '"&strPONumber&"')"
	else
		ssql = "UPDATE [PURCHASE ORDERS] SET "&strFieldName&" = '"&strValue&"' WHERE ([PO NUMBER] = '"&strPONumber&"')"
	end if
	
	response.write(ssql)
	dbc.execute(ssql)
	
	dbc.close
	set dbc=nothing
end if
%>


Here is the code for one of the text boxes in question:

<input type="text" id="txtSchdQty<%=i%>" name="txtSchdQty<%=i%>" value="<%=rs("SchdQty")%>" onChange="ValidateNumber('[SCHDQTY]', <%=rs("POLineID")%>, this.value, 'NonText')" onFocus="ChangeColor(this.id, <%=i%>)" onBlur="ChangeColorBlur(this.id, <%=i%>, 'White')" style="font-family: Verdana; font-size: 8pt; background-color:White" size="10" autocomplete="off" maxlength="50">


Here is the code for the ValidateNumber (it is vbscript; however, I am in a fixed IE environment)

sub ValidateNumber(Field, POLineID, Value, FieldType)
	if Not IsNumeric(Value) then
		msgbox("Field Must be Numeric!  Data Was Not Saved!")
		exit sub
	end if
	
	SaveRecordDetails Field, POLineID, Value, FieldType
end sub


So, you save an item on the textbox, it kicks off the ValidateNumber routine. That works correctly. In that routine, it kicks off the javascript AJAX functions. I know the data is being passed correctly from the vbscript to javascript as the alert url shows the data correctly. It doesn't save it all the time from the javascript function; however, if you plug in the url from the alert, it saves correctly everytime.

does anyone have any ideas?

I am not 100% sure on this, but I think it only happens when i change my number field from anything to 0. But, again, when I run the page seperate for saving, it saves 0 correctly. It appears to happen more when trying to save to 0 at least. Like, i'll change it from 0 to 25, then try to change it back to 0 right away, and it does not save. If I let it sit for a couple min and try again, then it saves it to 0.

< Message edited by dzirkelb1 -- 3/24/2009 12:01:18 >
jaybee

 

Posts: 14431
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: AJAX Help - save only works sometimes - 3/25/2009 7:06:25   
I know zip about Ajax, I've avoided it as there are so many issues with accessibility so anything I can come up with is just a wild guess but it sounds like something is getting stuck and that usually means caching issues.

I did a quick search and it seems Ajax is notorious for cache problems. Whether this is your issue??????? but it might be worth Googling for Ajax caching and having a read of some of the problems and solutions.



_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to dzirkelb1)
dzirkelb1

 

Posts: 1444
Joined: 10/5/2004
From: Cedar Rapids, Iowa
Status: offline

 
RE: AJAX Help - save only works sometimes - 3/25/2009 9:08:26   
Thanks for the suggestion! Well, so far, the cache makes sense. So, I placed a randon number in the querystring for the save page to force a non-cached page. It seems to work so far; however, I will wait until our network is getting pounded more to check it. Lets hope this works!

This means a lot of work for me, btw, as we have multiple ajax pages where a phantom non-save would happen, but its for the better!

(in reply to jaybee)
jaybee

 

Posts: 14431
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: AJAX Help - save only works sometimes - 3/25/2009 10:10:55   
LOL, yes the random number thing was the one I saw too. let us know how it works out.

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to dzirkelb1)
Page:   [1]

All Forums >> Web Development >> General Web Development >> AJAX Help - save only works sometimes
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts