Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Joomla组件Ajax调用:未捕获语法错误:意外标识符_Javascript_Jquery_Ajax_Joomla_Joomla3.0 - Fatal编程技术网

Javascript Joomla组件Ajax调用:未捕获语法错误:意外标识符

Javascript Joomla组件Ajax调用:未捕获语法错误:意外标识符,javascript,jquery,ajax,joomla,joomla3.0,Javascript,Jquery,Ajax,Joomla,Joomla3.0,我是Joomla、Javascript和JQuery方面的新手。 我正在编写Joomla3.x组件,并尝试在后端表单中使用Ajax调用 我已经编写了一个Ajax调用来动态更新我的edit.php中的一些字段(参见下面的代码)。我附上了大部分代码,因为我想知道我是否弄乱了javascript、Jquery和Joomla的东西 在chrome上运行时,我得到以下错误:uncaughtsyntaxerror:在Ajax调用的行方法“POST”处出现意外标识符 任何帮助都将不胜感激。 非常感谢你花时间回

我是Joomla、Javascript和JQuery方面的新手。 我正在编写Joomla3.x组件,并尝试在后端表单中使用Ajax调用

我已经编写了一个Ajax调用来动态更新我的edit.php中的一些字段(参见下面的代码)。我附上了大部分代码,因为我想知道我是否弄乱了javascript、Jquery和Joomla的东西

在chrome上运行时,我得到以下错误:uncaughtsyntaxerror:在Ajax调用的行方法“POST”处出现意外标识符

任何帮助都将不胜感激。 非常感谢你花时间回答我的问题

致意

埃里克


jQuery.noConflict();
函数checkAmount(){
//billable_items_table=document.getElementById(“#jform_billable_items_table_table”);
console.log(“表修改”);
//警报(可计费项目表值);
}
函数calculateAmount(){
billable_items_table=document.getElementById(“jform_billable_items_table_table”);
//
console.log(“保存的表”);
警报(可计费项目表值);
}
函数calculateVAT(){
控制台日志(“VAT修改”);
calculateVATAjax();
}
jQuery(文档).ready(函数($){
console.log(“准备就绪!”);
函数calculateVATAjax(){
var应纳税=document.getElementById(“jform_应纳税”);
var金额=document.getElementById(“jform金额+增值税”);
jQuery.ajax({
方法:“张贴”,
url:“index.php?option=com\u emc&task=invoice.calculateVAT&format=json”,
数据:{应税:应税价值,
金额:金额,金额,价值,
: 1
},
成功:功能(r){
if(!r.success&&r.message){
//成功标志设置为“false”,并给出主响应消息
//因此,您可以提醒它或将其插入到某个HTML元素中
警报(r.message);
}
if(r.messages){
//$app对象的所有排队消息都可以是简单的
//由Joomla的相应辅助函数呈现!
//它们将自动显示在模板的消息部分
伦德尔消息(r.messages);
}
document.getElementById(“jform\u VAT\u rate”).value=r.data.VATrate;
document.getElementById(“jform\u VAT\u amount”).value=r.data.VAT\u amount;
document.getElementById(“jform\u amount\u inc\u VAT”).value=r.data.amount\u inc\u VAT;
//if(r.data)
//{
//在这里,您可以访问响应的所有数据
//警报(r.data);
//}
},
失败:函数(xhr){
//达到这一点意味着Ajax请求本身没有成功
//所以JResponseJson从未被调用过
警报(“Ajax错误”);
},
错误:函数(文本,错误){
//达到这一点意味着服务器已响应Ajax请求,但是
//响应没有有效的JSON(如果出现PHP错误,有时会发生这种情况,
//新Ajax请求开发过程中的警告或通知)。
警报(“服务器已响应Ajax请求”+“\n”+错误+“\n”+文本);
}
});
}
//添加事件处理程序
美元(“#jform_应税”)。变更(计算税);
美元(“#jform#u billable_items_table_table”)。更改(支票金额);
$(“.save model data”)。单击(calculateAmount);
});

我肯定认为您将在上获得更多帮助。您的意思是我应该在我的问题中添加Joomla标记吗?不要访问Joomla stackexchange网站的链接。我肯定认为您将在上获得更多帮助。您的意思是我应该在我的问题中添加Joomla标记吗?不要访问Joomla stackexchange网站的链接。
<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_emc
 *
 * @copyright   Copyright (C) 2015 Eric LLANO. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('_JEXEC') or die('Restricted access');

JHtml::_('jquery.framework');

JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select');
JHTML::_('behavior.modal'); 

?>

<script type="text/javascript">

    jQuery.noConflict();

    function checkAmount() {
        //billable_items_table = document.getElementById("#jform_billable_items_table_table");
        console.log( "Table modified" );
        //alert(billable_items_table.value);
    }

    function calculateAmount() {
        billable_items_table =  document.getElementById("jform_billable_items_table_table");
        //
        console.log( "Table saved" );
        alert(billable_items_table.value);      
    }

    function calculateVAT() {
        console.log( "VAT modified" );
        calculateVATAjax();
    }

    jQuery(document).ready(function($){

        console.log( "ready!" );

        function calculateVATAjax() {
            var taxable =           document.getElementById("jform_taxable");
            var amount_exc_VAT =    document.getElementById("jform_amount_exc_VAT");

            jQuery.ajax({
                method: "POST",
                url: "index.php?option=com_emc&task=invoice.calculateVAT&format=json",
                data: { taxable: taxable.value,
                        amount_exc_VAT: amount_exc_VAT.value,
                        <?php  echo(JSession::getFormToken());?>: 1
                    },
                success: function(r) {
                    if (!r.success && r.message) {
                        // Success flag is set to 'false' and main response message given
                        // So you can alert it or insert it into some HTML element
                        alert(r.message);
                    }

                    if (r.messages) {
                        // All the enqueued messages of the $app object can simple be
                        // rendered by the respective helper function of Joomla!
                        // They will automatically be displayed at the messages section of the template
                        Joomla.renderMessages(r.messages);
                    }

                    document.getElementById("jform_VAT_rate").value = r.data.VATrate;
                    document.getElementById("jform_VAT_amount").value = r.data.VAT_amount;
                    document.getElementById("jform_amount_inc_VAT").value = r.data.amount_inc_VAT;
                    //if (r.data)
                    //{
                        // Here you can access all the data of your response
                        //alert(r.data);

                    //}
                },
                failure: function(xhr) {
                    // Reaching this point means that the Ajax request itself was not successful
                    // So JResponseJson was never called
                    alert('Ajax error');
                },
                error: function(text, error) {
                    // Reaching this point means that the Ajax request was answered by the server, but
                    // the response was no valid JSON (this happens sometimes if there were PHP errors,
                    // warnings or notices during the development process of a new Ajax request).
                    alert("Ajax request was answered by the server"+"\n"+error + "\n" + text);
                }
            });
        }

        // Add the event handlers
        $("#jform_taxable").change(calculateVAT);
        $("#jform_billable_items_table_table").change(checkAmount);
        $(".save-modal-data").click(calculateAmount);
    });

</script>