1

I have a form that displays 'item' properties. The user has the option of uploading files/attachments to this 'item'. Currently, in a div with class 'testing' displays the existing attachments for the item. The user uses an 'attach' button to attach files to the item they want to update. The files are never actually attached until the form is submitted with an 'update' button click event (which is what I want). The form submit is an ajax submit to an iframe. I want to use jquery to load a coldfusion page containing the query for finding currently attached items into my 'testing' div. My initial approach was to use jquery's load function after the form submit:

//In the JS file, the selected item is used in the CF query form.submit(); $('.testing').load('itemAttachments.cfm?itemID=' + selectedItem); 

I know my coldufusion query works, because it is a cfinclude in the 'testing' div and the page initially loads with the correct information. On the form submit, the jquery load returns the cf page, but with the same data and not the new attachments listed. When I refresh the page, the data is displayed correctly (i.e. with the new attachments listed). This leads me to believe that everything works right, but the jquery load is happening before the Oracle can process the query.

Is this correct? If so, how can I fix this? Thanks.

EDIT The form submits to a target with a hidden iframe.The issue is that both the form submit and the jquery .load() are using the same page, itemAttachments. But the jquery load() is getting the results first, before the form submit, even though the .load is after the form submit in the code.

5
  • check firebug or chrome developer tools for any errors. Commented Aug 10, 2012 at 18:27
  • @DG3 Unfortunately, I am limited to IE8. Commented Aug 10, 2012 at 18:34
  • i think you can use them just for debugging purposes. For IE8, probably fiddler would be helpful Commented Aug 10, 2012 at 19:15
  • I don't think your conclusion can be correct. The CF page won't return until it finishes the query. Doesn't the submit() trigger an entirely new page load? That may be firing before the AJAX call can complete. Commented Aug 11, 2012 at 0:48
  • @eaolson The form submits to a target with a hidden iframe.The issue is that both the form submit and the jquery .load() are using the same page, itemAttachments. But the jquery load() is getting the results first, before the form submit, even though the .load is after the form submit in the code. Commented Aug 13, 2012 at 12:25

2 Answers 2

1

This trick with iframe gives you 2 parallel request and perhaps .load wins the race. If you already using jquery, I've suggest that you should do post also with jquery and execute load (or even just use ajax response).

If you for some reason have to use iframe hack, then you need to attach event to iframe. For example you can launch it on iframe reloading:

$('#iframe').load(function(evt){ //do some checks $('.testing').load('itemAttachments.cfm?itemID=' + selectedItem); }); 
Sign up to request clarification or add additional context in comments.

2 Comments

The iframe is an empty/hidden one; I use it only for the target of the form submit. That is why I use the form.submit() in my js. I'm not sure there is a way to use a callback funtion when submitting a form like that. Or is there?
Why do you need this form submit, when you can use ajax submit? Or jquery plugin if u want it for file. Along with the file you can submit any other data and get response from the server with the same data, you were getting with $('.testing').load('itemAttachments.cfm?itemID=' + selectedItem);
0

I added the script for the jquery load to the coldfusion processing page. I gave it a scope of window.parent.document ie:

<SCRIPT LANGUAGE="JAVASCRIPT"> $(document).ready(function(){ $('.testing', window.parent.document).load('processForm.cfm?itemID=' + <cfoutput>#itemID#</cfoutput); }); </SCRIPT> 

This worked.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.