第一个函数的代码(记住它经过测试并且工作正常):
$('.create-invoice').on('click',function()
{
grab_invoice_data();
// Declare a variable
var jsonObj = invoice_data;
// Lets convert our JSON object
var postData = JSON.stringify(jsonObj);
// Lets put our stringified json into a variable for posting
var postArray = {json:postData};
//if cookie exists
var i_n = $('.inv-number').val();
$.cookie('lid', ++i_n, { expires: 365 } );
//invoices created
if( $.cookie('ic') ){
var ck_inv_created = ($.cookie('ic'));
$.cookie('ic', (++ck_inv_created));
} else {
$.cookie('ic', ++inv_created);
}
})
第二个函数的代码(它完美地运行。这是新添加的函数):
$(document).ready(function(){
$(".reloadpg").click(function(){
$.get("http://localhost/einvoice/inum.php", function(data) {
$(".on input").val(data);
});
});
});
问题是,当我将第二个函数放在我的代码中时,它工作但第一个函数停止工作!记住他们听同一个按钮..所以不同并尝试做这个代码:
$('.create-invoice').on('click',function()
{
grab_invoice_data();
// Declare a variable
var jsonObj = invoice_data;
// Lets convert our JSON object
var postData = JSON.stringify(jsonObj);
// Lets put our stringified json into a variable for posting
var postArray = {json:postData};
//Below is the code i added from the second function to the first its not working here.. when it was alone outside this function it will worked but it won't here
$.download("php/json.php", postArray, 'post');
$.get( "/einvoice/inum.php", function(data) {
$('.inv-number').val(data);
});
//Above is the code i added from the second function..
//below is the rest of the code for the function which was there from the beginning, keep in mind only the below code is bing executed the above is not.. its not refreshing the part of the page it should its calling the php script successfully tho, but i will have to refresh the page my self to see the number updated
//if cookie exists
var i_n = $('.inv-number').val();
$.cookie('lid', ++i_n, { expires: 365 } );
//invoices created
if( $.cookie('ic') ){
var ck_inv_created = ($.cookie('ic'));
$.cookie('ic', (++ck_inv_created));
} else {
$.cookie('ic', ++inv_created);
}
})
单击按钮时,我需要两个功能才能成功运行!任何帮助将不胜感激
答案 0 :(得分:0)
您可以尝试从第一个函数调用第二个函数。
$('.create-invoice').click(function(){
secondFunction();
//rest of code
});
var secondFunction = function(){
//code
};
答案 1 :(得分:0)
正如评论中所讨论的那样,问题是你不小心插入了一条并不存在的行:
$.download("php/json.php", postArray, 'post');
只需删除此行,它就可以正常工作。