jquery控制只监听数字_两个jQuery函数监听同一个按钮,但只有一个可以工作

Code for the first function(keeping in mind its tested and it works fine):

$('.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);

}

})

Code for the second function(it works perfectly. this is the newly added function):

$(document).ready(function(){

$(".reloadpg").click(function(){

$.get("http://localhost/einvoice/inum.php", function(data) {

$(".on input").val(data);

});

});

});

The problem is that when i placed the second function in my code it worked but the first function stopped from working! keeping in mind they listen to the same button.. so get disparate and tried to do this code:

$('.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);

}

})

i need both function to work successfully when the button is clicked not just one! any help would be appreciated

解决方案

As discussed in the comments, the problem is that you accidentally inserted a line which was not meant to be there:

$.download("php/json.php", postArray, 'post');

Just remove this line and it should all work.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值