Forked from anonymous/gist:a76e5bb4c065c8497a74a1ffd83b5b88
Created
April 13, 2017 15:08
-
-
Save aliaspooryorik/b14efd03ea37681e5447297b761d8598 to your computer and use it in GitHub Desktop.
Lucee jQuery.ajax and remote CFC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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