Jquery与Json和PHP
您好,我在jquery和php中使用post表单,表单调用其他页面并从jquery中使用json获取结果,例如,当我使用jquery并在php中调用此页面时,我从jquery中读取json得到以下结果:Jquery与Json和PHP,php,jquery,json,Php,Jquery,Json,您好,我在jquery和php中使用post表单,表单调用其他页面并从jquery中使用json获取结果,例如,当我使用jquery并在php中调用此页面时,我从jquery中读取json得到以下结果: <?php print '{"login":"datos_fails_lock"}'; ?> 在这种情况下的问题是,我只能显示这一点,没有包括在结果中的其他文本,如果包括更多的操作系统此代码脚本没有工作,我喜欢json检测此代码,但我也想显示html,目前我不能这样做 当我以j
<?php
print '{"login":"datos_fails_lock"}';
?>
在这种情况下的问题是,我只能显示这一点,没有包括在结果中的其他文本,如果包括更多的操作系统此代码脚本没有工作,我喜欢json检测此代码,但我也想显示html,目前我不能这样做
当我以jquery的形式调用其他页面时,我可以将其他信息作为html和json包含在这个页面中
对不起,我已经尽力解释了
问候 与其打印自己的json文本布局,为什么不使用PHP为您完成呢。这样,您就可以拥有包含html的数组,并让该函数对其进行编码 例如:
<?php
print json_encode(array('login' => 'datos_fails_lock'));
?>
与其打印自己的json文本布局,为什么不使用PHP为您打印呢。这样,您就可以拥有包含html的数组,并让该函数对其进行编码 例如:
<?php
print json_encode(array('login' => 'datos_fails_lock'));
?>
在PHP端:
<?php
// compute html
$html = '<div><p>...</p></div>';
// compute json
$json = '{"login":"datos_fails_lock"}';
$response = array('html' => $html, 'json' => $json);
print json_encode($response);
?>
在PHP端:
<?php
// compute html
$html = '<div><p>...</p></div>';
// compute json
$json = '{"login":"datos_fails_lock"}';
$response = array('html' => $html, 'json' => $json);
print json_encode($response);
?>
据我所知, 如果希望从php文件中获取json编码的值,并使用jquery显示调用该文件的内容,请执行以下操作:
$.post('ajax/process.php', function(data) {
$('.result').html(data.login);
$('.other_thing').html(data.something_else);
});
在php文件中:
<?
echo json_encode(array(
'login' => 'datos_fails_lock',
'something_else' => 'Other thing'
));
?>
据我所知, 如果希望从php文件中获取json编码的值,并使用jquery显示调用该文件的内容,请执行以下操作:
$.post('ajax/process.php', function(data) {
$('.result').html(data.login);
$('.other_thing').html(data.something_else);
});
在php文件中:
<?
echo json_encode(array(
'login' => 'datos_fails_lock',
'something_else' => 'Other thing'
));
?>
最佳内联解决方案:
<?php
$myObjectOrArray = (object) array('test' => array('test' => array('test' => 'testValue')));
$javascriptGateway = rawurlencode(json_encode(myObjectOrArray));
?>
<script type="text/javascript">
//<!--
var myObjectOrArray = JSON.stringify(unescape('<?php echo $javascriptGateway;?>'));
alert(myObjectOrArray.test.test.test); //result: testValue
//-->
</script>
//
我使用此解决方案,以便将包含特殊字符的php对象传递到javascript对象。最佳内联解决方案:
<?php
$myObjectOrArray = (object) array('test' => array('test' => array('test' => 'testValue')));
$javascriptGateway = rawurlencode(json_encode(myObjectOrArray));
?>
<script type="text/javascript">
//<!--
var myObjectOrArray = JSON.stringify(unescape('<?php echo $javascriptGateway;?>'));
alert(myObjectOrArray.test.test.test); //result: testValue
//-->
</script>
//
我使用此解决方案,以便将包含特殊字符的php对象传递到javascript对象。您能为我看到并创建其他对象提供代码示例吗,谢谢:)您能为我看到并创建其他对象提供代码示例吗,谢谢:)