我在自定义的WordPress插件中使用ajax时遇到了“Bad request”错误。

huangapple go评论117阅读模式
英文:

I'm getting "Bad request" using ajax in custom WordPress plugin

问题

I am trying to create a form in my first WordPress app, but the moment I send the Post data using $.ajax() I get the error "Bad request".

我正在尝试在我的第一个WordPress应用程序中创建一个表单,但是当我使用$.ajax()发送Post数据时,我收到"Bad request"错误。

Any help will be really appreciated.

非常感谢任何帮助。

My JS code:

我的JS代码:

  1. jQuery(document).ready(function($) {
  2. // Verify if my_ajax_obj is defined
  3. if (typeof my_ajax_obj !== 'undefined') {
  4. console.log(my_ajax_obj);
  5. // Capture the submit event of the form
  6. $("#dhl_guias_form").on("submit", function(event) {
  7. event.preventDefault();
  8. // Serialize form data and convert it to JSON
  9. var formData = $("#dhl_guias_form").serialize()
  10. console.log(formData);
  11. // Perform the POST request using $.ajax
  12. jQuery.ajax({
  13. type: "POST",
  14. url: my_ajax_obj.ajax_url,
  15. data: formData,
  16. action: 'astral_save_form',
  17. beforesend: function(){
  18. alert("hello");
  19. console.log("ajax");
  20. console.log(my_ajax_obj);
  21. console.log(my_ajax_obj.ajax_url);
  22. },
  23. nonce: my_ajax_obj.nonce,
  24. success: function(response) {
  25. // Request success
  26. console.log(response);
  27. console.log("OK");
  28. },
  29. error: function(xhr, status, error) {
  30. // Request error
  31. console.log(error);
  32. console.log("error");
  33. }
  34. });
  35. });
  36. } else {
  37. console.log("my_ajax_obj is not defined");
  38. }
  39. });

My PHP code:

我的PHP代码:

  1. <?php
  2. /*
  3. Plugin Name: Astral
  4. Plugin URI: https://www.example.com
  5. Description: Plugin description.
  6. Version: 1.0
  7. Author: Your Name
  8. Author URI: https://www.yourname.com
  9. */
  10. // Activate the plugin
  11. register_activation_hook(__FILE__, 'astral_plugin_activation');
  12. function astral_plugin_activation() {
  13. // Code to activate the plugin
  14. global $wpdb;
  15. $table_name = $wpdb->prefix . 'dhl_guias'; // Table name
  16. $charset_collate = $wpdb->get_charset_collate();
  17. $sql = "CREATE TABLE $table_name (
  18. id INT NOT NULL AUTO_INCREMENT,
  19. nombre VARCHAR(100) NOT NULL,
  20. direccion VARCHAR(100) NOT NULL,
  21. PRIMARY KEY (id)
  22. ) $charset_collate;";
  23. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  24. dbDelta($sql);
  25. }
  26. // Deactivate the plugin
  27. register_deactivation_hook(__FILE__, 'astral_plugin_deactivation');
  28. function astral_plugin_deactivation() {
  29. // Code to deactivate the plugin
  30. }
  31. function astral_create_menu() {
  32. add_menu_page(
  33. 'Astral', // Page title
  34. 'Astral Menu', // Menu title
  35. 'manage_options', // Capability
  36. 'astral-menu', // Menu slug
  37. 'astral_menu_callback', // Callback to display menu content
  38. 'dashicons-admin-generic', // Icon
  39. 1 // Menu position in the admin panel
  40. );
  41. }
  42. add_action('admin_menu', 'astral_create_menu'); // Create Menu
  43. function astral_menu_callback() {
  44. // Code to display the Astral menu content
  45. include plugin_dir_path(__FILE__) . 'astral_visual.php';
  46. }
  47. add_action( 'admin_enqueue_scripts', 'my_enqueue' );
  48. function my_enqueue( $hook ) {
  49. if ( 'toplevel_page_astral-menu' !== $hook ) {
  50. return;
  51. }
  52. wp_enqueue_script(
  53. 'ajax-script',
  54. plugins_url( 'js/astral.js', __FILE__ ),
  55. array( 'jquery' ),
  56. );
  57. $title_nonce = wp_create_nonce( 'title_example' );
  58. wp_localize_script(
  59. 'ajax-script',
  60. 'my_ajax_obj',
  61. array(
  62. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  63. 'nonce' => wp_create_nonce( 'nonce' )
  64. )
  65. );
  66. }
  67. add_action('wp_ajax_astral_save_form', 'astral_save_form');
  68. function astral_save_form() {
  69. check_ajax_referer('astral_ajax_nonce', 'nonce'); // Verify nonce for added security
  70. global $wpdb;
  71. $table_name = $wpdb->prefix . 'dhl_guias';
  72. $field1 = sanitize_text_field($_POST['field1']);
  73. $field2 = sanitize_text_field($_POST['field2']);
  74. $wpdb->insert(
  75. $table_name,
  76. array(
  77. 'id' => NULL,
  78. 'nombre' => $field1,
  79. 'direccion' => $field2
  80. )
  81. );
  82. wp_die(); // End the execution of the AJAX request
  83. }

My form (astral_visual.php):

我的表单(astral_visual.php):

  1. <form id="dhl_guias_form" method="POST">
  2. <input type="text" name="field1" placeholder="Campo 1" /><br>
  3. <input type="text" name="field2" placeholder="Campo 2" /><br>
  4. <button type="submit" id="save" name="save">GUARDAR</button>
  5. </form>
英文:

I am trying to create a form in my first WordPress app, but the moment I send the Post data using $.ajax() I get the error "Bad request".

我在自定义的WordPress插件中使用ajax时遇到了“Bad request”错误。

I tried several solutions, even using Chat GTP, but I can't fix this error.

Any help will be really appreciated.

My JS code:

  1. jQuery(document).ready(function($) {
  2. // Verificar si my_ajax_obj est&#225; definido
  3. if (typeof my_ajax_obj !== &#39;undefined&#39;) {
  4. console.log(my_ajax_obj);
  5. // Capturamos el evento submit del formulario
  6. $(&quot;#dhl_guias_form&quot;).on(&quot;submit&quot;, function(event) {
  7. event.preventDefault();
  8. // Serializamos los datos del formulario y los convertimos en JSON
  9. var formData = $(&quot;#dhl_guias_form&quot;).serialize()
  10. console.log(formData);
  11. // Realizamos la solicitud POST utilizando $.ajax
  12. jQuery.ajax({
  13. type: &quot;POST&quot;,
  14. url: my_ajax_obj.ajax_url,
  15. data: formData,
  16. action: &#39;astral_save_form&#39;,
  17. beforesend: function(){
  18. alert(&quot;hello&quot;);
  19. console.log(&quot;ajax&quot;);
  20. console.log(my_ajax_obj);
  21. console.log(my_ajax_obj.ajax_url);
  22. },
  23. nonce: my_ajax_obj.nonce,
  24. success: function(response) {
  25. // &#201;xito en la solicitud
  26. console.log(response);
  27. console.log(&quot;OK&quot;);
  28. },
  29. error: function(xhr, status, error) {
  30. // Error en la solicitud
  31. console.log(error);
  32. console.log(&quot;error&quot;);
  33. }
  34. });
  35. });
  36. } else {
  37. console.log(&quot;my_ajax_obj no est&#225; definido&quot;);
  38. }
  39. });

My PHP code:

  1. &lt;?php
  2. /*
  3. Plugin Name: Astral
  4. Plugin URI: https://www.ejemplo.com
  5. Description: Descripci&#243;n del plugin.
  6. Version: 1.0
  7. Author: Tu Nombre
  8. Author URI: https://www.tunombre.com
  9. */
  10. // Activar el plugin
  11. register_activation_hook(__FILE__, &#39;astral_plugin_activation&#39;);
  12. function astral_plugin_activation() {
  13. // C&#243;digo para activar el plugin
  14. global $wpdb;
  15. $table_name = $wpdb-&gt;prefix . &#39;dhl_guias&#39;; // Nombre de la tabla
  16. $charset_collate = $wpdb-&gt;get_charset_collate();
  17. $sql = &quot;CREATE TABLE $table_name (
  18. id INT NOT NULL AUTO_INCREMENT,
  19. nombre VARCHAR(100) NOT NULL,
  20. direccion VARCHAR(100) NOT NULL,
  21. PRIMARY KEY (id)
  22. ) $charset_collate;&quot;;
  23. require_once(ABSPATH . &#39;wp-admin/includes/upgrade.php&#39;);
  24. dbDelta($sql);
  25. }
  26. // Desactivar el plugin
  27. register_deactivation_hook(__FILE__, &#39;astral_plugin_deactivation&#39;);
  28. function astral_plugin_deactivation() {
  29. // C&#243;digo para desactivar el plugin
  30. }
  31. function astral_create_menu() {
  32. add_menu_page(
  33. &#39;Astral&#39;, // T&#237;tulo de la P&#225;gina
  34. &#39;Astral Menu&#39;, // T&#237;tulo del Men&#250;
  35. &#39;manage_options&#39;, // Capability
  36. &#39;astral-menu&#39;, // Slug del Men&#250;
  37. &#39;astral_menu_callback&#39;, // Callback para mostrar el contenido del men&#250;
  38. &#39;dashicons-admin-generic&#39;, // Icono
  39. 1 // Posici&#243;n del men&#250; en el panel de administraci&#243;n
  40. );
  41. }
  42. add_action(&#39;admin_menu&#39;, &#39;astral_create_menu&#39;); // Crear Men&#250;
  43. function astral_menu_callback() {
  44. // C&#243;digo para mostrar el contenido del men&#250; Astral
  45. include plugin_dir_path(__FILE__) . &#39;astral_visual.php&#39;;
  46. }
  47. add_action( &#39;admin_enqueue_scripts&#39;, &#39;my_enqueue&#39; );
  48. function my_enqueue( $hook ) {
  49. if ( &#39;toplevel_page_astral-menu&#39; !== $hook ) {
  50. return;
  51. }
  52. wp_enqueue_script(
  53. &#39;ajax-script&#39;,
  54. plugins_url( &#39;js/astral.js&#39;, __FILE__ ),
  55. array( &#39;jquery&#39; ),
  56. );
  57. $title_nonce = wp_create_nonce( &#39;title_example&#39; );
  58. wp_localize_script(
  59. &#39;ajax-script&#39;,
  60. &#39;my_ajax_obj&#39;,
  61. array(
  62. &#39;ajax_url&#39; =&gt; admin_url( &#39;admin-ajax.php&#39; ),
  63. &#39;nonce&#39; =&gt;wp_create_nonce( &#39;nonce&#39; )
  64. )
  65. );
  66. }
  67. add_action(&#39;wp_ajax_astral_save_form&#39;, &#39;astral_save_form&#39;);
  68. function astral_save_form() {
  69. check_ajax_referer(&#39;astral_ajax_nonce&#39;, &#39;nonce&#39;); // Verificar el nonce para mayor seguridad
  70. global $wpdb;
  71. $table_name = $wpdb-&gt;prefix . &#39;dhl_guias&#39;;
  72. $field1 = sanitize_text_field($_POST[&#39;field1&#39;]);
  73. $field2 = sanitize_text_field($_POST[&#39;field2&#39;]);
  74. $wpdb-&gt;insert(
  75. $table_name,
  76. array(
  77. &#39;id&#39; =&gt; NULL,
  78. &#39;nombre&#39; =&gt; $field1,
  79. &#39;direccion&#39; =&gt; $field2
  80. )
  81. );
  82. wp_die(); // Finaliza la ejecuci&#243;n de la solicitud AJAX
  83. }

My form (astral_visual.php):

  1. &lt;form id=&quot;dhl_guias_form&quot; method=&quot;POST&quot;&gt;
  2. &lt;input type=&quot;text&quot; name=&quot;field1&quot; placeholder=&quot;Campo 1&quot; /&gt;&lt;br&gt;
  3. &lt;input type=&quot;text&quot; name=&quot;field2&quot; placeholder=&quot;Campo 2&quot; /&gt;&lt;br&gt;
  4. &lt;button type=&quot;submit&quot; id=&quot;save&quot; name=&quot;save&quot;&gt;GUARDAR&lt;/button&gt;
  5. &lt;/form&gt;

答案1

得分: 0

你的代码中有一些错误和问题。

注意:由于Stack Overflow是一个英语社区,我已经翻译了大部分内容。

PHP主要插件代码:

  1. <?php
  2. /*
  3. 插件名称:Astral
  4. 插件URI:https://www.example.com
  5. 描述:插件描述。
  6. 版本:1.0
  7. 作者:你的名字
  8. 作者URI:https://www.yourname.com
  9. */
  10. // 插件激活 - 在数据库中创建'dhl_guias'表
  11. register_activation_hook(__FILE__, 'astral_plugin_activation');
  12. function astral_plugin_activation() {
  13. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  14. global $wpdb;
  15. dbDelta("
  16. CREATE TABLE {$wpdb->prefix}dhl_guias (
  17. id INT NOT NULL AUTO_INCREMENT,
  18. nombre VARCHAR(100) NOT NULL,
  19. direccion VARCHAR(100) NOT NULL,
  20. PRIMARY KEY (id)
  21. ) {$wpdb->get_charset_collate()}");
  22. }
  23. // 插件停用
  24. register_deactivation_hook(__FILE__, 'astral_plugin_deactivation');
  25. function astral_plugin_deactivation() {
  26. // 你的代码
  27. }
  28. // 在WordPress管理中添加菜单
  29. add_action('admin_menu', 'astral_create_menu');
  30. function astral_create_menu() {
  31. add_menu_page(
  32. 'Astral', // 页面标题
  33. 'Astral菜单', // 菜单标题
  34. 'manage_options', // 权限
  35. 'astral-menu', // 菜单别名
  36. 'astral_menu_callback', // 用于内容输出的函数
  37. 'dashicons-admin-generic', // 图标
  38. 1 // 在管理菜单中的位置
  39. );
  40. }
  41. // 菜单回调函数
  42. function astral_menu_callback() {
  43. // 显示内容的代码(调用外部文件)
  44. include plugin_dir_path(__FILE__) . 'astral_visual.php';
  45. }
  46. // 注册JavaScript外部文件
  47. add_action( 'admin_enqueue_scripts', 'my_enqueue' );
  48. function my_enqueue( $hook ) {
  49. if ( 'toplevel_page_astral-menu' !== $hook ) {
  50. return;
  51. }
  52. wp_enqueue_script( 'astral-ajax-script',
  53. plugins_url( 'js/astral.js', __FILE__ ),
  54. array( 'jquery' ), '1.0.0', true );
  55. wp_localize_script(
  56. 'astral-ajax-script',
  57. 'astral_params',
  58. array(
  59. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  60. 'nonce' => wp_create_nonce( 'astral_nonce' )
  61. )
  62. );
  63. }
  64. add_action('wp_ajax_astral_save_form', 'astral_save_form');
  65. function astral_save_form() {
  66. // 检查Ajax请求以防止外部不安全的请求
  67. check_ajax_referer('astral_nonce', 'security');
  68. global $wpdb;
  69. if( isset($_REQUEST['form_data'])) {
  70. $data = array(); // 初始化
  71. parse_str($_REQUEST['form_data'], $data);
  72. if( isset($data['fullname']) && isset($data['address'])
  73. && ! empty($data['fullname']) && ! empty($data['address']) ) {
  74. // 在数据库中插入一些数据
  75. $wpdb->insert( "{$wpdb->prefix}dhl_guias", array(
  76. 'id' => NULL,
  77. 'nombre' => sanitize_text_field($data['fullname']),
  78. 'direccion' => sanitize_text_field($data['address'])
  79. ) );
  80. echo "成功!数据已保存到数据库中";
  81. } else {
  82. echo "警告:未填写某些表单字段";
  83. }
  84. } else {
  85. echo "警告:未发送表单数据";
  86. }
  87. wp_die(); // 静默结束(必需的)
  88. }

HTML表单(添加到astral_visual.php外部文件中):

  1. <form id="dhl-guias" method="POST">
  2. <label for="fullname">Nombre completo:</label><br>
  3. <input type="text" id="fullname" name="fullname" placeholder="Agrega tu nombre completo aquí" /><br>
  4. <label for="address">Dirección:</label><br>
  5. <input type="text" id="address" name="address" placeholder="Añade tu dirección aquí" /><br><br>
  6. <button type="submit" id="save" name="save">Guardar</button><br>
  7. <p class="message"></p>
  8. </form>

jQuery / JavaScript astral.js外部文件:

  1. jQuery( function($) {
  2. // 检查是否定义了本地化变量astral_params
  3. if (typeof astral_params !== 'undefined') {
  4. console.log(astral_params);
  5. // 在提交表单事件上
  6. $('form#dhl-guias').on('submit', function(e) {
  7. e.preventDefault(); // 阻止默认表单提交行为
  8. // 序列化表单数据
  9. var formData = $(this).serialize()
  10. // 通过Ajax发送POST请求
  11. $.ajax({
  12. type: "POST",
  13. url: astral_params.ajax_url,
  14. datatype: 'json',
  15. data: {
  16. 'action': 'astral_save_form',
  17. 'form_data': formData,
  18. 'security': astral_params.nonce
  19. },
  20. beforesend: function( xhr ){
  21. console.log("beforesend");
  22. console.log(xhr);
  23. },
  24. success: function(response) {
  25. $('form p.message').html(response); // 添加消息
  26. console.log("success");
  27. console.log(response);
  28. },
  29. error: function(xhr, status, error) {
  30. console.log("error");
  31. console.log(xhr);
  32. console.log(error);
  33. }
  34. });
  35. });
  36. } else {
  37. console.log('"astral_params"未定义');
  38. }
  39. });

经过测试,当填写表单时,会将条目添加到数据库表中。

英文:

There are some mistakes and errors in your code.

Note: As Stack Overflow is an English-speaking community, I have translated mostly everything.

The PHP main plugin code:

  1. &lt;?php
  2. /*
  3. Plugin Name: Astral
  4. Plugin URI: https://www.example.com
  5. Description: Plugin description.
  6. Version: 1.0
  7. Author: Your name
  8. Author URI: https://www.yourname.com
  9. */
  10. // Plugin activation - Create &#39;dhl_guias&#39; table in database
  11. register_activation_hook(__FILE__, &#39;astral_plugin_activation&#39;);
  12. function astral_plugin_activation() {
  13. require_once(ABSPATH . &#39;wp-admin/includes/upgrade.php&#39;);
  14. global $wpdb;
  15. dbDelta(&quot;
  16. CREATE TABLE {$wpdb-&gt;prefix}dhl_guias (
  17. id INT NOT NULL AUTO_INCREMENT,
  18. nombre VARCHAR(100) NOT NULL,
  19. direccion VARCHAR(100) NOT NULL,
  20. PRIMARY KEY (id)
  21. ) {$wpdb-&gt;get_charset_collate()}&quot;);
  22. }
  23. // Plugin deactivation
  24. register_deactivation_hook(__FILE__, &#39;astral_plugin_deactivation&#39;);
  25. function astral_plugin_deactivation() {
  26. // your code
  27. }
  28. // Add a menu in the WordPress admin
  29. add_action(&#39;admin_menu&#39;, &#39;astral_create_menu&#39;);
  30. function astral_create_menu() {
  31. add_menu_page(
  32. &#39;Astral&#39;, // Page title
  33. &#39;Astral Menu&#39;, // Menu title
  34. &#39;manage_options&#39;, // Capability
  35. &#39;astral-menu&#39;, // Menu slug
  36. &#39;astral_menu_callback&#39;, // The function to be called for content output
  37. &#39;dashicons-admin-generic&#39;, // Icon
  38. 1 // Position in the Admin menu order
  39. );
  40. }
  41. // Function called by the menu
  42. function astral_menu_callback() {
  43. // Code to display the content (calling an external file)
  44. include plugin_dir_path(__FILE__) . &#39;astral_visual.php&#39;;
  45. }
  46. // Register JavaScript external files
  47. add_action( &#39;admin_enqueue_scripts&#39;, &#39;my_enqueue&#39; );
  48. function my_enqueue( $hook ) {
  49. if ( &#39;toplevel_page_astral-menu&#39; !== $hook ) {
  50. return;
  51. }
  52. wp_enqueue_script( &#39;astral-ajax-script&#39;,
  53. plugins_url( &#39;js/astral.js&#39;, FILE ),
  54. array( &#39;jquery&#39; ),&#39;1.0.0&#39;, true );
  55. wp_localize_script(
  56. &#39;astral-ajax-script&#39;,
  57. &#39;astral_params&#39;,
  58. array(
  59. &#39;ajax_url&#39; =&gt; admin_url( &#39;admin-ajax.php&#39; ),
  60. &#39;nonce&#39; =&gt; wp_create_nonce( &#39;astral_nonce&#39; )
  61. )
  62. );
  63. }
  64. add_action(&#39;wp_ajax_astral_save_form&#39;, &#39;astral_save_form&#39;);
  65. function astral_save_form() {
  66. // Check the Ajax request to prevent external insecure requests
  67. check_ajax_referer(&#39;astral_nonce&#39;, &#39;security&#39;);
  68. global $wpdb;
  69. if( isset($_REQUEST[&#39;form_data&#39;])) {
  70. $data = array(); // initializing
  71. parse_str($_REQUEST[&#39;form_data&#39;], $data);
  72. if( isset($data[&#39;fullname&#39;]) &amp;&amp; isset($data[&#39;address&#39;])
  73. &amp;&amp; ! empty($data[&#39;fullname&#39;]) &amp;&amp; ! empty($data[&#39;address&#39;]) ) {
  74. // Inserting the some data in the database
  75. $wpdb-&gt;insert( &quot;{$wpdb-&gt;prefix}dhl_guias&quot;, array(
  76. &#39;id&#39; =&gt; NULL,
  77. &#39;nombre&#39; =&gt; sanitize_text_field($data[&#39;fullname&#39;]),
  78. &#39;direccion&#39; =&gt; sanitize_text_field($data[&#39;address&#39;])
  79. ) );
  80. echo &quot;Success! The data has been saved to the database&quot;;
  81. } else {
  82. echo &quot;Warning: Some form fields have not been filled&quot;;
  83. }
  84. } else {
  85. echo &quot;Warning: The form data has not ben sent&quot;;
  86. }
  87. wp_die(); // End silently (mandatory)
  88. }

The HTML form (added to astral_visual.php external file):

  1. &lt;form id=&quot;dhl-guias&quot; method=&quot;POST&quot;&gt;
  2. &lt;label for=&quot;fullname&quot;&gt;Nombre completo:&lt;/label&gt;&lt;br&gt;
  3. &lt;input type=&quot;text&quot; id=&quot;fullname&quot; name=&quot;fullname&quot; placeholder=&quot;Agrega tu nombre completo aqu&#237;&quot; /&gt;&lt;br&gt;
  4. &lt;label for=&quot;address&quot;&gt;Direcci&#243;n:&lt;/label&gt;&lt;br&gt;
  5. &lt;input type=&quot;text&quot; id=&quot;address&quot; name=&quot;address&quot; placeholder=&quot;A&#241;ade tu direcci&#243;n aqu&#237;&quot; /&gt;&lt;br&gt;&lt;br&gt;
  6. &lt;button type=&quot;submit&quot; id=&quot;save&quot; name=&quot;save&quot;&gt;Guardar&lt;/button&gt;&lt;br&gt;
  7. &lt;p class=&quot;message&quot;&gt;&lt;/p&gt;
  8. &lt;/form&gt;

The jQuery / JavaScript astral.js external file

  1. jQuery( function($) {
  2. // check that the localized variable astral_params is defined
  3. if (typeof astral_params !== &#39;undefined&#39;) {
  4. console.log(astral_params);
  5. // On submitting the form event
  6. $(&#39;form#dhl-guias&#39;).on(&#39;submit&#39;, function(e) {
  7. e.preventDefault(); // Stop default form post action
  8. // Serializing form data
  9. var formData = $(this).serialize()
  10. // Sending the post request via Ajax
  11. $.ajax({
  12. type: &quot;POST&quot;,
  13. url: astral_params.ajax_url,
  14. datatype: &#39;json&#39;,
  15. data: {
  16. &#39;action&#39;: &#39;astral_save_form&#39;,
  17. &#39;form_data&#39;: formData,
  18. &#39;security&#39;: astral_params.nonce
  19. },
  20. beforesend: function( xhr ){
  21. console.log(&quot;beforesend&quot;);
  22. console.log(xhr);
  23. },
  24. success: function(response) {
  25. $(&#39;form p.message&#39;).html(response); // add a message
  26. console.log(&quot;success&quot;);
  27. console.log(response);
  28. },
  29. error: function(xhr, status, error) {
  30. console.log(&quot;error&quot;);
  31. console.log(xhr);
  32. console.log(error);
  33. }
  34. });
  35. });
  36. } else {
  37. console.log(&#39;&quot;astral_params&quot; is not defined&#39;);
  38. }
  39. });

Tested and works. When the form is filled, an entry is added to the database table.

huangapple
  • 本文由 发表于 2023年7月7日 06:13:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定