Dumbfounded by ajax call of cfc function failure

Code below.

<form action="" method="post">
	Enter your name: <input type="text" name="name" id="name"> <input type="button" name="add" value="Go" onclick="send()">
</form>

<script
  src="https://code.jquery.com/jquery-3.5.1.min.js"
  integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
  crossorigin="anonymous">

	function send() {
		console.log('fn called');
		em = document.getElementById('name').value;
		console.log(em);
		$.post("./savename.cfc?method=savedata", {dname:'+em+'});
	}
</script>	


cfc

<cfcomponent output="false">

	<cffunction name="savedata" access="remote">
		<cfargument name="dname" type="string" required="yes">
		<cftry>
			<cfquery datasource="myds">
				insert into wemail(email)
				values ('#arguments.dname#');			
			</cfquery>
		<cfcatch type="database">
			<cfset success=0>
		</cfcatch>
		</cftry>		
	</cffunction>
	
</cfcomponent>

direct calling via browser ( test ):
http://127.0.0.1/myapp/savename.cfc?method=savedata&dname=‘John’

Err msg:

### This page contains the following errors:

error on line 16 at column 9: Opening and ending tag mismatch: meta line 0 and head

### Below is a rendering of the page up to the first error.

thanks.

You are passing the variable em as the string +em+, rather than its value (e.g. “John”).

1 Like

holy molly! Thank you. But then, I shouldn’t get an error, instead, it should have inserted bad data instead. Since I’m getting an error, it seems there’s some syntax error, which one?

You missing a </script> after the jquery.js and a open <script> for the inline-script.

But that also stands in your error message :

Opening and ending tag mismatch
1 Like

Please see above with comments. Thanks.

could you post the error message?