我对jQuery调用有点问题。我有这段代码:
<script type="text/javascript">
jQuery('input[name="location"]').click(function(){
var data = {clocation : jQuery(this).val(), department : $('input[name="department"]:checked').val()};
jQuery.ajax({
url: "/new.php",
type:'POST',
data: data,
dataType: 'html',
success: function(result){
jQuery('#div-custom').html(result).show();
}
});
});
</script>
这是new.php:
echo 'Here is your data:';
print_r($custom_data[0]); //This contains a mix of HTML and JavaScript
echo 'End of Data';
new.php文件生成HTML和JavaScript混合返回。如果我手动访问new.php并传入数据,则内容呈现没有问题。但是,当它通过jQuery传回时,JavaScript部分失败了。我知道它必须以某种方式与dataType相关,但我不确定如何克服这个问题。
感谢您的帮助!