console.log(data) 总是返回 0,我查看了其他答案,他们都说要么 add die(); 或添加操作 wp_ajax_nopriv... 我已经完成了。其他人可以帮我找到解决方案吗?
JavaScript:
$('#formID').submit(function(e)
{
e.preventDefault();
ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
var data = {
action: 'testFunction',
}
jQuery.post(ajaxurl, data, function(data)
{
console.log(data);
});
});
Run Code Online (Sandbox Code Playgroud)
Functions.php 函数
add_action( 'wp_ajax_add_testFunction', 'testFunction' );
add_action( 'wp_ajax_nopriv_add_testFunction', 'testFunction' );
function testFunction()
{
echo "test";
die();
}
Run Code Online (Sandbox Code Playgroud) 在Laravel 5.2控制器中使用PHP Carbon时,变量似乎彼此绑定.所以改变一个会影响其他人;
PHP功能:
$now = Carbon::now();
var_dump($now);
$from = $now;
$from->startOfYear();
var_dump('-----------------------------------');
var_dump($now, $from);
Run Code Online (Sandbox Code Playgroud)
结果是:
object(Carbon\Carbon)[225]
public 'date' => string '2016-02-13 21:55:36.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
string '-----------------------------------' (length=35)
object(Carbon\Carbon)[225]
public 'date' => string '2016-01-01 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
object(Carbon\Carbon)[225]
public 'date' => string '2016-01-01 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
Run Code Online (Sandbox Code Playgroud)
设置$from到年初也受到影响$now …