Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework

I am using the WordPress Plugin Boilerplate to show a form to the user via shortcode. I am just a little confused of the

I am using the WordPress Plugin Boilerplate to show a form to the user via shortcode. I am just a little confused of the flow of data not so much the syntax to do it.

My Main Public Class has a method that creates a form when a user adds the shortcode. I have a class that can take the form data and build a URL that calls an API.

This is how I thought it should work: 1. Javascript function fires when "Submit" is clicked. It checks to make sure the form is complete if so use AJAX to pass the data to my Processesing script. 2. The script builds the URL and calls the API and data should be returned.

Question: Once the data is returned can I pass the data and update the original page with the form to show the data? This is were I am not 100% sure how to do.

So the user experience should include completing the form, submitting (maybe a loader animation) and the data appears below the form.

****I don't need code I am just looking for an direction on the flow of data.**

I am using the WordPress Plugin Boilerplate to show a form to the user via shortcode. I am just a little confused of the flow of data not so much the syntax to do it.

My Main Public Class has a method that creates a form when a user adds the shortcode. I have a class that can take the form data and build a URL that calls an API.

This is how I thought it should work: 1. Javascript function fires when "Submit" is clicked. It checks to make sure the form is complete if so use AJAX to pass the data to my Processesing script. 2. The script builds the URL and calls the API and data should be returned.

Question: Once the data is returned can I pass the data and update the original page with the form to show the data? This is were I am not 100% sure how to do.

So the user experience should include completing the form, submitting (maybe a loader animation) and the data appears below the form.

****I don't need code I am just looking for an direction on the flow of data.**

Share Improve this question asked Jun 10, 2019 at 22:39 DenoteoneDenoteone 2091 gold badge4 silver badges12 bronze badges 2
  • Yes, you can. You can submit arbitrary data via AJAX and update the page after receiving a response from the server. But maybe you should post your code, if you need further help. – Sally CJ Commented Jun 11, 2019 at 0:30
  • 1 Thank you for confirming and will provide code once i try and get some results on my own. Thanks! – Denoteone Commented Jun 11, 2019 at 5:54
Add a comment  | 

1 Answer 1

Reset to default 0

Take a look at the codex for AJAX in Plugins. It provides example of how WordPress expects AJAX requests are made and how to return information back to the request in javascript.

The request gets routed through admin-ajax.php which locates and action in PHP. The rest is up to you.

Note: you must echo/print the content for it to be returned in the body of the response. It's helpful for it to be encoded with wp_json_encode() as well.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745416823a4626786.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信