我有一个方法,通过AJAX调用后端,从MySQL数据库获取一个blob文件,由PHP检索.
问题是PHP变量包含一个字符串,但AJAX调用是空的,PDF函数不起作用.
这是AJAX代码,它被调用.
self.showPDF = function() {
$.ajax({
type: 'GET',
url: BASEURL + 'index.php/myprofile/openUserPDF/' + auth,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
})
.done(function(data) {
console.log(data);
window.open("data:application/pdf," + escape(data));
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert("Could not open pdf" + errorThrown);
})
.always(function(data) {});
}
Run Code Online (Sandbox Code Playgroud)
这是后端的PHP函数,我使用的是CodeIgniter框架.
public function openUserPDF($token) {
if ($this->input->is_ajax_request()) {
$userid = $this->myajax->getUserByAuth($token);
if ($userid) {
/* If we have an impersonated user in the session, let's use him/her. */
if (isset($_SESSION['userImpersonated'])) {
if ($_SESSION['userImpersonated'] > 0) …Run Code Online (Sandbox Code Playgroud) 我知道这感觉像是一个重复的问题,但我已经尝试了所有可能的方式来让我的 ajax 请求工作,但它只是无法做到。这是ajax代码。ajax 调用是从 index.html 中的 js 文件触发的
self.getJSON = () => {
$.ajax({
type: 'POST',
url: 'https://iot-backend-metropolia.herokuapp.com/api/user' ,
contentType: 'application/json; charset=utf-8',
dataType: "json",
})
.done(function(result) {
console.log(result);
})
.fail(function(xhr, status, error) {
alert(error);
})
.always(function(data){
});
}
Run Code Online (Sandbox Code Playgroud)
我尝试了 2 种方法。
1) npm install cors
app.use(cors())
2) // Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8888');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// …Run Code Online (Sandbox Code Playgroud) 我有一个从Codeigniter中的html视图生成的PDF,现在我想将其发送到我的电子邮件中,但是我遇到的麻烦是它显示中有一个字符串,$pdf但是在我的电子邮件中发送时为空。这是整个Codeigniter函数。
public function generatePDF()
{
require_once(APPPATH.'third_party/dompdf/dompdf_config.inc.php');
$dompdf = new Dompdf();
$msg = $this->load->view('credit_agreement_view', '', true);
$html = mb_convert_encoding($msg, 'HTML-ENTITIES', 'UTF-8');
$dompdf->load_html($html);
$paper_orientation = 'Potrait';
$dompdf->set_paper($paper_orientation);
// Render the HTML as PDF
$dompdf->render();
$pdf = $dompdf->output();
// sending the pdf to email
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'support@aurorax.co';
$config['smtp_pass'] = '#######';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether …Run Code Online (Sandbox Code Playgroud) 我试图获取从第一个日期到第二个日期的天数,然后从第二个日期到第三个日期,依此类推.我有这样的数组
$dates = array(
2016 - 02 - 01,
2016 - 03 - 01,
2016 - 04 - 01,
2016 - 05 - 01,
2016 - 06 - 01,
2016 - 07 - 01,
2016 - 09 - 01,
2016 - 11 - 01,
2016 - 12 - 01,
2017 - 01 - 01,
2017 - 12 - 01
);
Run Code Online (Sandbox Code Playgroud)
我想知道从2016-02-01到2016-03-01,然后从2016-03-01到2016-04-01的天数等等,如果您注意到日期中存在一些差距他们跳了超过1个月.我希望它在这样的数组中
array()(
[0] => 0,
[1] => 30,
[2] => 60
//so on ...
)
Run Code Online (Sandbox Code Playgroud)
这是我如何做到这一点,但我得到的错误uninitialized string offset ,我猜我做的方式很可能是错误的 …
我在比较名称字符串时遇到问题.我有3个变量
$fullname = 'MASNAD HOSSAIN NEHITH';
$firstName = 'Masnad';
$LastName = 'Nehith';
$fullname2 = 'MÄSNAD HOSSAIN NEHITH';
$firstName2 = 'Mäsnad';
$LastName2 = 'Nehith';
Run Code Online (Sandbox Code Playgroud)
我想使用strpos以查看全名中是否存在名字,但是strpos区分大小写.
我尝试使用pregmatch的正则表达式,但我不确定它是如何工作的.
$pregmatch = preg_match("/$fullname/", $firstName);
if($pregmatch){
echo " it matches";
}
$pregmatch2 = preg_match("/$fullname2/", $firstName2);
if($pregmatch2){
echo " it matches";
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在heroku上使用jenkins,但遇到一个问题是,现在将jenkins部署到heroku之后,它想获取管理员密码,并向我显示此路径 /app/.jenkins/secrets/initialAdminPassword
我ssh进入我的heroku应用程序并尝试使用cat(path),但它显示在我的heroku bash上没有类似的路径。
要设置我的heroku服务器,请遵循以下https://gist.github.com/jordansissel/2313443
我正在尝试制作一个闹钟,它会在完成时发出声音.因此,例如,我设置警报应该开始的时间18:00:00和当前时间17:59:00,所以基本上警报应该在1分钟内启动.
我尝试这样做:
var x = '18:00:00';
var t = new Date(x) - new Date();
setTimeout(function(){ alert("Hello"); }, t);
Run Code Online (Sandbox Code Playgroud)
这不起作用,不知道为什么.错误是NaN.