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:
here is the url that is passed as an example: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 } }
Which outputs this as the sql query:Code:https://ecis.deei.com/receiving-recg-save.asp?UpdateDetails=Yes&Value=0&FieldName=[SCHDQTY]&POLineID=438988&FieldType=NonText
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:Code:UPDATE PORECGS1 SET [SCHDQTY] = 0 WHERE (POLineID = 438988)
Here is the code for one of the text boxes in question:Code:<!-- #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 the ValidateNumber (it is vbscript; however, I am in a fixed IE environment)Code:<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">
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.Code: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
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.


Reply With Quote


Bookmarks