-1

有人可以告诉我如何添加这个 php 代码:

<?php  include('shopping_cart_temp.php'); ?>

进入这个 javascript 行:

$('.cart_status').append('<p class="json-productname">' + retObj.product_name );
4

3 回答 3

0

使用 AJAX 调用:

$.get('shopping_car_temp.php', function(result){
    // display the data returned, value store in 'result'
});
于 2012-07-15T14:44:50.927 回答
0

进一步来说,

$.get('shopping_car_temp.php', function(result){
   $('.cart_status').append('<p class="json-productname">' + result );
});

在您的 shopping_car_temp.php 文件中,仅回显 retObj.product_name。如果您需要回显多个内容,您可能希望将它们格式化为 JSON 对象。您可以在以下位置阅读这些内容: http: //api.jquery.com/jQuery.get/

于 2012-07-15T15:05:33.117 回答
0

PHP 是一种服务器端语言,而 Javascript 是一种客户端语言。当您在浏览器中请求 php 页面时,服务器会处理该请求,解释 PHP 代码并将 HTML 页面发送给您。然后,只有当 HTML 页面在您的浏览器中时,javascript 才会被解释,因此您不能从这里添加 PHP 代码,因为它无法被解释。

As @TurdPile said, you can make an ajax request to get the code from shopping_cart_temp.php and then manipulate it, but you should read some ajax tutorial to understand exactly how it works because it could be quite hard to understand

于 2012-07-15T15:05:39.937 回答