Home  >  Article  >  Backend Development  >  用ajax传递变量给PHP(使用了smarty),提醒未定义变量

用ajax传递变量给PHP(使用了smarty),提醒未定义变量

WBOY
WBOYOriginal
2016-06-13 12:15:57860browse

用ajax传递变量给PHP(使用了smarty),提示未定义变量
JS源码:
function get_value_optgroup(form){
var opts;
var subject_class;
        var url; 
opts=sub_class.options[sub_class.selectedIndex].parentNode.attributes;
subject_class=opts["label"].value;
//---------------------------------------
//使用ajax发送选中的运算类
url = "compute.php?subject_class="+subject_class;
xmlhttp.open("POST",url,true);
//---------------------------------------
}

PHP代码(compute.php):
header ( "Content-type: text/html; charset=UTF-8" );  //设置文件编码格式
require("system/system.inc.php");   //包含配置文件
var_dump($_POST['subject_class']);
?>

报错:Undefined index: subject_class in D:\wamp\www\cp\compute.php

各位,帮帮忙吧!
------解决思路----------------------

引用:
Quote: 引用:

在php中改成$_REQUEST['subject_class']接收试试


谢谢你。问题已经解决了。现在有个新问题,我从PHP接收的responseText中的中文值乱码。这个怎么解决?


保证表单页面header声明、php文件和数据库都是utf8编码就不会乱了
------解决思路----------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

在php中改成$_REQUEST['subject_class']接收试试


谢谢你。问题已经解决了。现在有个新问题,我从PHP接收的responseText中的中文值乱码。这个怎么解决?


保证表单页面header声明、php文件和数据库都是utf8编码就不会乱了


的确如你所说,全都是utf-8的,但是还是出问题了


直接在浏览器访问接口,打印json,然后到http://www.bejson.com/看下~或者用var_dump来一步步检查
------解决思路----------------------
乱码一般刚开始都会遇到!
确保文件编码,文本编码都是统一的utf-8!  有时候你虽然加了声明字符集的头信息!但你的文件不是utf8格式的也不行!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn