简体   繁体   English

Wordpress儿童主题中的AJAX内部500错误

[英]AJAX Internal 500 Error in Wordpress Children-Theme

I got this Ajax code on Js/Jq block (/buscador/menuLateral/menu-libros.php): 我在Js / Jq块(/buscador/menuLateral/menu-libros.php)上获得了这个Ajax代码:

$.ajax({
  url: '<?= get_stylesheet_directory_uri(); ?>' +
    '/buscador/buscador-functions.php',
  type: 'POST',
  data: {
    sendCheckedVal: 'yes',
    tipo: 'editorial',
    valor: valor_recogido,
    archivo: this_file_id.toString()
  },
  success: function(data) {
    alert('Checked value !');
  }
});

Values on this file exists and got some value, I tried seeing it with a GET on a Stringify. 该文件上的值存在并且具有一定的价值,我尝试在Stringify上使用GET对其进行查看。

And this, must be getted in a file like this ( /buscador/buscador-functions.php) : 而且,必须将其放入这样的文件中( /buscador/buscador-functions.php)

<?php
    if (ISSET($_POST['sendCheckedVal'])){
       echo 'hi, u reached here' ;
    }
?>

The values doesn't passes from js code file to next. 值不会从js代码文件传递到next。

I get this error on console: 我在控制台上收到此错误:

POST [WP-URL-HIDDEN-ON-PURPOSE]/themes/ChildrenNewspaper/buscador/buscador-functions.php 500 (Internal Server Error) 开机自检[WP-URL-隐藏时目的] /themes/ChildrenNewspaper/buscador/buscador-functions.php 500(内部服务器错误)

On right side of the line-error : 在行错误的右侧:

jquery.min.js:2 jquery.min.js:2

Someone knows how to repair this on ajax working on a wordpress theme.Thanks 有人知道如何在使用wordpress主题的ajax上修复此问题。

Issue is here : alert('hi, u reached here'); 问题在这里: alert('hi, u reached here'); . alert() is not PHP function it is javascript function. alert()不是PHP函数,而是javascript函数。 So instead of it you can use echo or return 因此,您可以使用echoreturn代替它

<?php
    if (isset($_POST['sendCheckedVal'])){
       echo 'hi, u reached here';
    }
?>

To start you off, alert is a javascript function. 首先, alert是一个javascript函数。 In php you need to echo out values to the page; 在php中,您需要向页面echo值;

If you want to do it with JS you need to print out js. 如果要使用JS进行打印,则需要打印出js。

echo "<script type='text/javascript'>alert('hi, u reached here');</script>";

Or you can echo out the vars to the page. 或者你可以echo出瓦尔页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM