【发布时间】:2012-10-15 01:26:09
【问题描述】:
我给出另一个代码例如 这是我的 some3.php 代码:(第一个文件) :
<head>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('p').click(function(){
var who = $('input#who').val();
var why = $('input#why').val();
$('#geting').load('file2.php',{who:who,why:why},function(applyData){
if ( applyData == 'YEY . Ye have hi' ){
alert('OKKK data is ok ');
} else{
alert('Nooo We dont have requested output');
}
});
});
});
</script>
</head>
<body>
<p> click </p>
<input type="text" id="who">
<br>
<input type="text" id="why">
<div id="geting" align="center">
</div>
</body>
我这是我的 file2.php:
<?php
echo "1";
echo "2";
if($_REQUEST['who'] == "hi"){
$myVariable = "YEY . Ye have hi";
echo $myVariable;
} else{
$myVariable = "The out put is not Hi";
echo $myVariable;
}
?>
它不起作用,为什么?因为我们有 echo "1" 和 echo "2" 我希望 jquery 只检查 $myVariable 数据而不是整个 php 回调!我想我必须使用 json 但我不知道如何
【问题讨论】:
-
错误是什么?你为什么用
toString()? -
你是伊朗人吗? - 回显字符串时,无需使用
toString方法。 -
例如,如果我在 file2.php 中再添加 1 个回声,则它只是做 else{ alert('ok');这条线!我必须在 jquery 中使用什么来检查我在 php 输出中的 $myVariable 数据?
-
看来你想要的是JSON,你可以在PHP中创建一个key->value数组然后
json_encode()结果。 -
是的,我是伊朗人,所以如果我清理 .toString() 我可以在我的 file2.php 中有更多输出?