Forum Moderators: open
Here is what I have now. I'm new to AJAX, but I'm starting to understand what most of the code is doing.
The ajax.
<script type="text/javascript"><!--
function ajaxFunction(searchTerm){
xmlHttp=new XMLHttpRequest(); [i]//I shortened this from the full version for brevity on Webmaster World[/i]
} xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
[i]// Get the data from the server's response[/i]
}
} xmlHttp.open("POST","failedSearchAJAX.cfm",true);
xmlHttp.send(searchTerm); function sendData(){
var searchTerm = document.getElementById("searchTerm");
ajaxFunction(searchTerm);
}
//--></script> The HTML
<form id="failedSearch" action="javascript:(sendData());">
<p>Did you find what you were looking for?
<input id="no-btn" name="no-btn" title="No" type="submit" value="No" />
</p>
<input type="hidden" name="searchTerm" value="#url.criteria#" />
</p>
</form> The ColdFusion (failedSearchAJAX.cfm)
<cfquery name="AddData" datasource="Arbor" dbtype="ODBC">
INSERT INTO Forms_Failed_Searches (searchTerm)
values ('#form.failed-search#')
</cfquery> I can get as far as ajaxFunction() when I click the button, but after that, I'm lost.
xmlHttp.open("POST","failedSearchAJAX.cfm",true);
xmlHttp.send(searchTerm);
to
xmlHttp.open("POST","failedSearchAJAX.cfm?searchterm=" + searchterm,true);
xmlHttp.send(searchTerm);
and
<cfquery name="AddData" datasource="Arbor" dbtype="ODBC">
INSERT INTO Forms_Failed_Searches (searchTerm)
values ('#form.failed-search#')
</cfquery>
to
<cfquery name="AddData" datasource="Arbor" dbtype="ODBC">
INSERT INTO Forms_Failed_Searches (searchTerm)
values ('#searchterm#')
</cfquery>