php - 在不重新加载页面的情况下运行 PHP API 调用
问题描述
我有一个多步骤表单(HTML / JS / PHP),表单数据在提交后被发送到后端,导致页面重新加载。
当用户进入表单的新页面(单击下一步按钮)时,是否可以将数据实时传递到后端?
<?php
require_once dirname(__FILE__) . '/MailWizzApi/Autoloader.php';
MailWizzApi_Autoloader::register();
// configuration object
$config = new MailWizzApi_Config(array(
'apiUrl' => 'http://email.mddasd.de/api/index.php',
'publicKey' => 'SAMPLEKEY',
'privateKey' => 'SAMPLEKEY',
// components
'components' => array(
'cache' => array(
'class' => 'MailWizzApi_Cache_File',
'filesPath' => dirname(__FILE__) . '/MailWizzApi/Cache/data/cache', // make sure it is writable by webserver
)
),
));
// now inject the configuration and we are ready to make api calls
MailWizzApi_Base::setConfig($config);
// start UTC
date_default_timezone_set('UTC');
$email = $_POST ['email'];
$name = $_POST['name'];
$phone = $_POST['telephone'];
if (isset($_POST['branch_0_answers']) && $_POST['branch_0_answers'] != "")
{
foreach($_POST['branch_0_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$grundflaeche .= $_POST['grundflaeche-grundstueck'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
if (isset($_POST['branch_1_answers']) && $_POST['branch_1_answers'] != "")
{
foreach($_POST['branch_1_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$wohnflaeche .= $_POST['wohnflaeche-haus'] . "\n";
$grundflaeche .= $_POST['grundflaeche-haus'] . "\n";
$baujahr .= $_POST['baujahr'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
if (isset($_POST['branch_2_answers']) && $_POST['branch_2_answers'] != "")
{
foreach($_POST['branch_2_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$wohnflaeche .= $_POST['wohnflaeche-wohnung'] . "\n";
$baujahr .= $_POST['baujahr'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
if (isset($_POST['branch_3_answers']) && $_POST['branch_3_answers'] != "")
{
foreach($_POST['branch_3_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$gewerbeflaeche .= $_POST['gewerbeflaeche'] . "\n";
$grundflaeche .= $_POST['grundflaeche-gewerbe'] . "\n";
$baujahr .= $_POST['baujahr'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
foreach($_POST['branch_1_1_answers'] as $value)
{
$stand.= trim(stripslashes($value)) . "\n";
};
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$response = $endpoint->create('ma503j6m97b75', array(
'EMAIL' => $email,
'TELEFON' => $phone,
'NAME' => $name,
'ART' => $art,
'GEWERBEFLAECHE' => $gewerbeflaeche,
'WOHNFLAECHE' => $wohnflaeche,
'GRUNDFLAECHE' => $grundflaeche,
'BAUJAHR' => $baujahr,
'PLZ' => $plz,
'STAND' => $stand
));
?>
.php 使用最终的提交按钮执行。
感谢您的回答。
解决方案
推荐阅读
- javascript - React - Formik - 字段数组 - 实现可重复的表单字段
- 8085 - 如何在 8085 汇编器中创建十六进制数列表?
- bash - 为什么这个 4 行 bash 脚本不起作用?
- python - 使用子进程、pty 和线程池的死锁
- ruby-on-rails - 缓存时忽略某些属性
- cpanel - 编辑 www 目录中的文件后,cPanel 抛出 503 错误
- java - 如何在可完成的期货流中展平列表?
- mysql - 由于多字节字符,带有 maxlength 个字符的数据输入的 html 输入文本字段超过了数据库列宽
- python - Tensorflow 2 中的 tf.contrib.layers.fully_connected()?
- algorithm - 给定高度的时间序列,如何计算“起飞”和“着陆”时间?