Highlighted

Best way to do a jQuery AJAX in JSON format calls in CFM file

Engaged ,
Feb 01, 2016

Copy link to clipboard

Copied

Instead of using cfhttp in my CFM file, I like to use jQuery AJAX in JSON to do the query. Should I just simply putting the JS script on the CFM page? Or, do all of the work in a .js file and calling this .js file in the CFM page to display and formatting? Or should I just use the .js file to make the JSON calls and also targeting the IDs in the CFM file for display purposes?

Thank you.

The standard way to include a .js file.

<script type="text/javascript" src="/path/to/myJSfile.js"></script>

HTH,

^_^

Views

561

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Best way to do a jQuery AJAX in JSON format calls in CFM file

Engaged ,
Feb 01, 2016

Copy link to clipboard

Copied

Instead of using cfhttp in my CFM file, I like to use jQuery AJAX in JSON to do the query. Should I just simply putting the JS script on the CFM page? Or, do all of the work in a .js file and calling this .js file in the CFM page to display and formatting? Or should I just use the .js file to make the JSON calls and also targeting the IDs in the CFM file for display purposes?

Thank you.

The standard way to include a .js file.

<script type="text/javascript" src="/path/to/myJSfile.js"></script>

HTH,

^_^

Views

562

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 01, 2016 0
LEGEND ,
Feb 01, 2016

Copy link to clipboard

Copied

It depends upon whether or not you're going to be submitting CF data as part of the AJaX call.

Personally, I use inline JavaScript/jQuery, just in case I need to do anything regarding CF variables, etc.  But if you don't need to pass anything CF generated to the AJaX, then a .js file will work, fine.

var thisForm = $('#formName').serializeArray();

$.ajax({

    type: "POST",

    url: "/path/to/function.cfc?method=myFunction",

    data: {formData : thisForm},

contentType: "JSON"

    }).done(function(data){

              var datab = JSON.parse(data);

              ...  //whatever you need to do with the returned data

              });

HTH,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 01, 2016 1
Engaged ,
Feb 01, 2016

Copy link to clipboard

Copied

Thanks! That is very helpful. No, I don't need to pass anything. I just need to do a get. So, if I do an external .js file, how to I reference that file in .cfm file?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 01, 2016 0
LEGEND ,
Feb 01, 2016

Copy link to clipboard

Copied

The standard way to include a .js file.

<script type="text/javascript" src="/path/to/myJSfile.js"></script>

HTH,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 01, 2016 0
2Charlie LATEST
Engaged ,
Feb 01, 2016

Copy link to clipboard

Copied

Awesome! I thought I need to do something special with ColdFusion CFM. Thanks again!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 01, 2016 1