Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliaspooryorik/b14efd03ea37681e5447297b761d8598 to your computer and use it in GitHub Desktop.
Save aliaspooryorik/b14efd03ea37681e5447297b761d8598 to your computer and use it in GitHub Desktop.
Lucee jQuery.ajax and remote CFC
The html...
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h3>Submit Some Hidden Form Data</h3>
<form id="theForm">
<input name="image_name" type="hidden" value="DC001-041217.jpg">
<input name="item_num" type="hidden" value="WKRP-90210">
<button type="submit">Submit</button>
</form>
<div id="theResult"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#theForm").submit(function(e){
$.ajax({
type: "POST",
url: "/Request.cfc",
data: {
"method": 'testFunction',
"image_name": $("input[name=image_name]").val(),
"item_num": $("input[name=item_num]").val()
},
dataType: "json" // returned value from server is expected to be in a json format.
}).done(function(data){ // on ajax success.
$("#theResult").html(data);
})
e.preventDefault();
});
});
</script>
</body>
</html>
The CFC...
component output="false" {
remote string function testFunction(image_name, item_num) output=false {
var toSerialize = "";
toSerialize = {
"image_name"=arguments.image_name,
"item_num"=arguments.item_num
};
return serializeJSON(toSerialize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment