Coldfusion/Ajax Question
Say I POST something through ajax to a .cfm file which has a
query that will run based on the information passed. How do you
read in coldfusion what was passed with the XMLHttpRequest POST
object? For example. I want to have a text box where you can input
an id number and have it reference a page that runs a coldfusion
query to get the persons name. How do I read the data that was
passed to the coldfusion page from the POST method.
Any help is appreciated.
A few changes...
<script language = "javascript">
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new
ActiveXObject("Microsoft.XMLHTTP");
function getData(dataSource, divID, inputID)
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
var data = inputID + '=' +
document.getElementById(inputID).value;
XMLHttpRequestObject.open("POST", dataSource,1);
XMLHttpRequestObject.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
XMLHttpRequestObject.onreadystatechange = function()
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
XMLHttpRequestObject.send(data);
</script>
</head>
<body>
<H1>Test Ajax</H1>
<form>
<input type = "button" value = "Search SUID"
onclick = "getData('page2.cfm', 'targetDiv', 'suid')">
<input type = "text" name="suid" id="suid">
</form>
<div id="targetDiv">
<p>Display Data Goes Here.</p>
</div>
Here is what I changed:
function getData(dataSource, divID, inputID)
--added inputID argument. This is the id of the textbox
var data = inputID + '=' +
document.getElementById(inputID).value;
--gets the data to send from the textbox and formats it as
"suid=value".
XMLHttpRequestObject.open("POST", dataSource, 1);
--changed "GET" to "POST"; also added 1 to tell it to process
asynchronously
XMLHttpRequestObject.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
--added this line to set the request header for a form
<input type = "button" value = "Search SUID"
onclick = "getData('page2.cfm', 'targetDiv', 'suid')">
--added the id of the text box to the argument list
<input type = "text" name="suid" id="suid">
--gave it an id
Let me know how it works.
Similar Messages
-
ColdFusion.Ajax.submitForm ResultHandler Question
I am developing an CF Ajax based solution in which I use
ColdFusion.Ajax.submitForm to pass form values to a CFC for
processing via Java Script. My question is related to the Java
Script resultHandler and whether or not there is an easy way to
return the results from the CFC to handler.
My Java Script looks like this...
function InsertRec() {
ColdFusion.Ajax.submitForm('MyForm',
'service.cfc?method=InsertRec', resultInsertHandler,
resultErrorHandler);
My CFC looks like this.. (condensed)
<cffunction name="insertRec" access="remote" output="no"
returntype="numeric">
<cfargument name="NAME">
<cfargument name="Phone">
<cfquery name="recInsert" datasource="#request.DS#">
<cfset NEW_NUMBER = updatedNum( )> <-- Getting new #
from another table via CFC
INSERT INTO MYTABLE
(NUMBER, NAME, PHONE)
Values (' #NEW_NUMBER# ' , ' #ARGUMENTS.NAME# ' , '
#ARGUMENTS.PHONE# ' )
</cfquery>
<cfreturn NEW_NUMBER>
</cffunction>
What I'm trying to do is return the value of NEW_NUMBER from
the CFC back to resultInsertHandler so I can use it in a Java
Script alert msg. Any ideas or thoughts would be greatly
appreciated.
Regards
Martin FranklinMMFranklin wrote:
> What I'm trying to do is return the value of NEW_NUMBER
from the CFC back to
> resultInsertHandler so I can use it in a Java Script
alert msg. Any ideas or
> thoughts would be greatly appreciated.
Something like this I would presume.
function resultInsertHandler(returnMsg)
alert(returnMsg); -
CF8 / IIS7 / ColdFusion.Ajax.submitForm errorhandler not working
We make use of ColdFusion.Ajax.submitForm to do the login for our site. If the user/password provided is not found I do a cfthrow with a custom
error message that gets picked up by the errorHandler and updates the screen with the message "User not found". This worked fine till we upgraded
the server to IIS7. Now all I get is the "Internal Server Error."
I have googled the issue and searched these forums and found various threads about changing the errorMode or setting the existingResponse to passthrough in the IIS7 config. I have tried these and still not gotten anything to work. The only change I get is if I update the coldfusion config to
not pass in the HTTP error codes but in that case my error message simply becomes "OK". Not too helpful of a message.
My question is. Has anyone else run into these issues on IIS7 with Coldfusion 8 and if so, how did you configure the server to stop blocking the custom
errors? Any help would be great.
Thanks in advance.See, Joecopely's reply in this thread, that might resolve your issue,
http://forums.adobe.com/thread/532051?tstart=30
HTH -
ColdFusion.Ajax.submitForm error handler problem with AppleWebKit-based browsers
All-
When using an AppleWebKit-based browser (i.e. Safari or
Chrome), the
message argument of the Coldfusion.Ajax.submitForm error
handler always contains the string "OK", regardless of what error
was cfthrown by my CFM form handler.
Recall that the signature for the error handler is this:
MyFormErrorHandler = function( code, message )
In other browsers (i.e. IE or Firefox), the
message argument of the error handler properly contains the
message that was cfthrown by my form handler.
Can anyone offer any guidance for this problem? Thanks in
advance for your help.
-JoshI was testing on IE8, Windows7 Starter. I don't have IE6 available to test on. Can test on IE7 a bit later on, but I have to fart-arse around with a VM to get it ready, so I'll do that after work.
I tested multiple submits both via clicking between the tabs within one main "request" as well as multiple entire requests (like via refreshing the whole browser window). I had no problems.
I think you're being quite optimistic ot expect AJAX stuff to work reliably on IE6. IE6 crashes. That's what it's most famous for doing. One needs to expect crashes if one pushes it (push it anywhere than out the window, that is). And your client company's IT dept should be lined up against a wall and shot for still running it. That's professionally negligent IMO. But... you probably don't need to be told that.
Adam -
ColdFusion.Ajax.submitForm no longer works in IE10? any solutions
I have the following code, it works fine in IE8 & IE9 but stopped working in IE10, does anyone know why? the alert is displayed and it re-loads the page...it just doens't call the Ajax call..any help need to get this working again ASAP! Thanks.
function submitaddsitemed(){
alert('test');
ColdFusion.Ajax.submitForm('frm_testmed','test_add.cfm',callback,errorHandler,false);
location.reload();I have seen a similar and possibly related issue with IE10. I don't use ColdFusion's ajax routines and instead use jquery but I have found that using ajax with a POST fails on some IE10 users whereas GET works all the time. Like your symptom, no alert or error of any kind displayed or logged. It does not fail for all IE10 users, only some which leads me to believe there is a security setting somewhere in IE to not allow ajax POST requests but I have not spent enough time to determine the issue -- I cannot duplicate the issue with my hands on IE10 testing.
-
(cf9) Coldfusion.Ajax.submitForm 'does nothing'...
I'm using cffileupload, and calling the following javascript function with the 'onuploadcomplete', here's the cffileupload code:
<cffileupload
addbuttonlabel = "#request.uiTextBrowse#"
align = "center"
bgcolor = "blue"
clearbuttonlabel = "#request.uiTextClear#"
deletebuttonlabel = "#request.uiTextDelete#"
extensionfilter = "#l_fileExt#"
hideUploadButton = "false"
maxfileselect = "#session.fileUpload.maxFiles#"
maxuploadsize = "#session.fileUpload.maxSize#"
name = "fileUploader"
url = "#homeDir#/member/utilities/files/act_uploadFiles.cfm"
progressbar = "true"
stoponerror = "true"
title = "#session.fileUpload.Title#"
uploadbuttonlabel = "#request.uiTextUpload#"
width = "400"
onerror = "uploadError"
oncomplete = "uploadComplete"
[B]onuploadcomplete = "uploadFinished"[/B]
/>
function uploadFinished(){
alert('in uploadedFinished');
Coldfusion.Ajax.submitForm('filesToUploadForm','#homeDir#/member/utilities/files/act_proc essUploadedFiles.cfm',uploadProcessed, uploadProcessedError);
After checking about abazillion times I'm convinced I've got everything spelled correctly. The url is correct (checked 'viewsource'). The callback and error javascript functions:
function uploadProcessed(rtnText){
alert("in uploadPorcessed, text returned: ");
function uploadProcessedError(code, msg)
alert("Error!!! " + code + ": " + msg);
The upload works fine, files are uploaded. I know I'm getting into the uploadFinished as I get the alert which is directly in front of the Coldfusion.Ajax.Submit call. But after that alert, nothing. No error, nothing. Any ideas what are some common causes of behavior (or better, 'lack of' behavior) like that? The '#homeDir#/member/utilities/files/act_processUploadedFiles.cfm' file is in the same directory as the template being processed, but I can't find much about whether the full path is needed. If I just use 'act_processUploadedFiles.cfm'' I get the same (lack of) behavior.Hmmmm...
The ColdFusion Fairy visited me last night, and left a working ColdFusion.Ajax.submitForm call under my pillow...
In other words, it works this morning, and I don't know what I did to fix it!!!! -
ColdFusion.Ajax.submitForm Return a Value
The below code. I am trying is to pass a value to a CFC and
return a 0 or as 1.
But the response back with Asynch ColdFusion.Ajax.submitForm
is returning a bunch of javascript code and other stuff. All I am
expecting is just one value of either a 0 or 1. Can some one look
at the below and tell me what I am doing wrong. This form submits
to itself then I validate an input form. If its there, I pass the
value to cfcObviously it looks like you can not have <cfsetting
enablecfoutputonly="yes"> set in a cfm page that has Bind values
to a CFC, the behavior is unpredictable. I had to create an action
page to do the Asynch submit now it is returning a blank popup OK
form. The problem is still there and not returning any value
atall. -
Richtext fails with coldfusion.ajax.submitForm in IE
Hi all,
got a cfform containing a cftextarea with richtext = true, invoking the FCKeditor. The form is inside a cflayoutarea and to maintain the page view I'm doing the calling forumAddPost to do the submission using coldfusion.ajax.submitform, processing it through a CFC method....shown below.
The CFC simply writes to the database and once returned, the handler navigates the layoutarea to the mainpage.
function forumAddPost() {
ColdFusion.Ajax.submitForm('formnewpost', 'groups.cfc?method=forumNewPosts', forumAddPostHandler, errorHandler);
function forumAddPostHandler(result) {
ColdFusion.navigate('forum_showtopics_search.cfm?subject_id=<cfoutput>#group.forumid#</cf output>&searchtext=', 'MOD2');
function errorHandler(code, msg)
alert('error '+code+': '+msg);
This code works fine in Chrome or Firefox, but in IE it fails and closes IE down. If I remove the richtext option the posting works fine, so I've established it's something to do with the FCKeditor and the ajax posting method, but can't work out what?!
Anyone have any ideas?
Cheers
PhilI was testing on IE8, Windows7 Starter. I don't have IE6 available to test on. Can test on IE7 a bit later on, but I have to fart-arse around with a VM to get it ready, so I'll do that after work.
I tested multiple submits both via clicking between the tabs within one main "request" as well as multiple entire requests (like via refreshing the whole browser window). I had no problems.
I think you're being quite optimistic ot expect AJAX stuff to work reliably on IE6. IE6 crashes. That's what it's most famous for doing. One needs to expect crashes if one pushes it (push it anywhere than out the window, that is). And your client company's IT dept should be lined up against a wall and shot for still running it. That's professionally negligent IMO. But... you probably don't need to be told that.
Adam -
Can ColdFusion.Ajax.submitForm be used with a CF Flash Form ?
Hello,
Adobe has provided a great example of how
ColdFusion.Ajax.submitForm can be used to submit forms without
refreshing or redirecting the page (
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=JavaScriptFcns_01.html),
but does anyone know whether it can be used with flash forms ?
The attached code from the example compiles and runs
perfectly when the form has not been defined as flash, but when you
change <cfform name="myform"> to <cfform name="myform"
format="flash">, submitting produces the following error, likely
because it no longer recognizes the form name/ID:
Error!!! -1: ColdFusion.Ajax.submitForm: Form not found, form
id: myform
Does anyone know how to integrate this feature into a flash
form ?
Thanks !
LucienObviously it looks like you can not have <cfsetting
enablecfoutputonly="yes"> set in a cfm page that has Bind values
to a CFC, the behavior is unpredictable. I had to create an action
page to do the Asynch submit now it is returning a blank popup OK
form. The problem is still there and not returning any value
atall. -
Coldfusion.ajax.submitform httpMethod
Hello,
Any one has an
coldfusion.ajax.submitform httpMethod post example? I am
trying to submit all the form elements as form variables instead of
url variables.
Please a working example will help alot.
Thanks
EZhave you looked in the cfml reference manual?
download from adobe.com if you do not have one.
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/ -
I have a few questions about CF 11. I have just installed CF 11 on a Windows 8 server. This
is an all new server and software installation. It isn’t to where it can be
viewed outside of our network just yet until we have everything installed and
running properly on it. When it is all complete we will turn off the current
server and change the name of this one and make it public. We have the
certificate on it from the live site. So the name of the certificate and the
name of the server do not match.I have had my websites on CF 7, CF 8 and CF 9
servers previously.
We have used mappings on all of our previous versions with image tags and ahref tags. Have
things changed in CF 11 to not allow this anymore? An example is <img
src="/PACTlogin/loginIMages/LoginPicture1.jpg" alt="Login Image"
/>.(/PACTlogin is the mapping) We use the mappings like this because we have
dynamic pages being built. The same goes for ahref tags. An example of it is <a
href="/pact/pactacademy/Index.cfm">PACT Academy</a> (/pact
is the mapping). I have the mapping set up in the administrator just like I
have used on all previous versions of CF. On CF 11 it says the image is
missing. When you right click on the image it is actually looking for the image
in a folder called PACTlogin or pact. Which doesn’t actually exist because it
is a mapping. The mappings continue to work as expected in CF tags like
cflocation or cfinclude. What is the work around to get this to work again? Do
you create an application variable in the Application.cfc and use it in the tag
like <img src="<cfoutput>#application.Addr#</cfoutput>/login/loginIMages/LoginPicture1.jpg"
alt="" />? Is there a better way to do this? What are some ideas?
I have googled lots of things and haven’t come up with much except that CF is being
used with HTML 5 and since HTML tags like img and ahref are not cf tags it
doesn’t recognize the link as a mapping as it did before. Is this correct?
I have taken and created an application variable on Application.cfc and used it in place of
the mappings and it still isn’t working. An example is <img src="<cfoutput>#application.Addr#</cfoutput>/login/loginIMages/LoginPicture1.jpg"
alt="login Image" />. Any ideas on why this won’t work either?
Here is what my page looks like now.
This is what the page looks like when I go directly to the image in the browser.
It is totally blank. Not even an X…
I would appreciate any help or ideas. Thank you in advance.If your HTML <IMG> tag is pointing to a normal image (PNG, JPG, GIF, etc...) then ColdFusion is not involved whatsoever. Only the webserver, IIS, serves images using the code you've entered. IIS has no idea what your CF Mappings are. CFLocation and CFInclude, however, are CF tags and so are processed by CF and are aware of the CF mappings.
What I imagine has happened is your old servers has Virtual Directories defined in IIS that were identical to your CF Mappings. Compare you directory structures in IIS between your old and new servers to see if this is the case. -
The company that hosts our site only has a CF5 and a CF6
server. When it comes to CF, I wouldn't even call myself a rookie.
More like an observer who knows that it exisits and is hoping to
someday be a rookie. Before I invest the time and money, is
anything created in CF7 going to work on their servers?
Sub-Question: Should I just wait for the release of CF8?Should I just wait for the release of CF8?
Of course - ask Adobe for the official answer. But in the
past, the
makers of ColdFusion, first Allair then Macromedia, where
pretty good at
allowing users who purchased a new license of CF, just before
an upgrade
is released, to get the upgrade when it came out. The grace
period was
a few months. -
Ajax question - driving me mad!!
Hi
I am still trying to get my head around the whole Ajax "game"
perhaps someone can help me. I have a page which shows lets say 10
rows in a table representing different analyses the user has saved.
rather than simply click thru to the page "produc.cfm" I want to
show each row as
<tr><td><a href="product.cfm"
onmouseover="getproductdetails('#databaseid#');"">R#reportnumber#
#provider# #reporttitle#</a></td></tr>
with the idea that in a div I show the main results in a side
part of the page as the user scrolls down like a preview. I have a
cfc which seems to be working correctly:
<cfcomponent>
<cffunction name="getreportstructure" access="remote"
returnFormat="json"
output="false">
<cfargument name="databaseid" required="no" type="string"
default="0">
<cfset var mystruct=structnew()>
<cfquery name="getd" datasource="timm-spiraldatabase"
maxrows="1">
select * from report
where databaseid =#databaseid#
</cfquery>
<cfset mystruct.closingdate=getd.closingdate>
<cfset mystruct.strikedate=getd.strikedate>
<cfreturn mystruct>
</cffunction>
</cfcomponent>
so when the user hovers over the row I want to show the
closingdate and strikedate in the div
have tried a 100 cominations over the last 3 hours without
success - help!!
Thanks
TimThis,
onmouseover="getproductdetails('#databaseid#');"">
is looking for a javascript function called
getproductdetails. Do you have one? -
Simple AIR ajax question? One html file or many?
I am a new ajax air developer and was wondering if it's a better practice to use one html file in my app or many html files? So far I have been testing with many html files using javascript location.href to send the user to another html page when they click different navigation buttons. This works although there is a clear webpage "loading" feel to the app due to a temporary white screen displaying over the app as it loads the next page (maybe for a couple milliseconds). Not a huge deal but still feels somewhat unprofessional since regular desktop apps do not have this "flicker" occur when changing navigation. Now if I use a single html file (where I load html using javascript) this does not occur but the file feels very large and bloated. Anyone have any suggestions of how I can eliminate the flicker that occurs using many files (perhaps I am not loading the file the correct way into the native window) or am I stuck with a single file if I want there to be no flicker?
I'll say become a Flex/AIR developer
-
Hello Community!
I have two questions regarding CF lists:
1-) I have a list that has the values 1,2,
As you can see, the comma at the end of that string will make mymy program break because that list of comma delimited values is being used in a SQL statement: in(1,2,)
How do I remove that comma at the end of my list?
2-) I have a list with the values 1,,3
How do I get rid of that unnecesary comma? How do I fill in the space between , and , with a value so it's 1,value,3 instead?
Thanks!
Ysais.if mylist = '1,2,'
then you could make your SQL in(#removechars(mylist, len(mylist), 1)#)
essentially removing the last character.
to get rid of the unnecessary comma you could CFLOOP though the list and create another list 'mynewlist' this time not including anything that's blank
ie if mylist = '1,,3'
<cfset mynewlist = ''>
<cfloop list="#mylist#" index="getitem">
<cfif getitem neq ''>
<cfset mynewlist = listappend(mynewlist, #getitem#)>
</cfif>
</cfloop>
mynewlist becomes '1,3'
Maybe you are looking for
-
Problem with printing PDFs as 6 slides pr. page.
Hi! I am having trouble printing PDFs as handouts with 6 slides on one page. I go through all the settings for the printer, and the print comes out ok, but the slides are printed up side down and in the wrong order. Even though I have set the order i
-
Post an incoming payment ( check ) against an invoice
Hi I am trying to post an incoming payment ( cheque ) against an invoice. I keep getting no matching records found ( odbc error -2028 ) Has anyone got a simple example I could use as a comparison please ? Thanks Regards Andy
-
IMovie 10.0.7 - Adjust Colours Numerically?
I have a question about iMovie 10.0.7, which is currently the latest version of iMovie. If you Adjust colours (using the Multislider control, the Saturation slider, or Color Temperature slider) is there a way to bring up numbers, so that you can Adju
-
Hi, I am implementing a BADI in the BP transaction on the R/3 side. For a certain select statement in the BADi, I am doing a sy-subrc <> 0 check, and if it is not equal to 0, I need to raise an exception. I am raising an exception of type E. The popu
-
JMS Messaging Bridge ( communication across domains)
Following is the Scenario We have 2 Weblogic domains, Domain A ( running on port 2000) and Domain B (running on port 3000) In Domain A I want to look up a Queue which is in Domain B and send a message on that that Queue. So the requirement is to send