imrulhasan273
1 month ago

How can I convert `data[1]` to integer format in JQuery-Ajax?

Posted 1 month ago by imrulhasan273
 $.ajax({
                type: "get",
                url: "{{ route('ajaxReview.rating') }}",
                data: { id: value },
                success: function(data) {
                    console.log(data);
                    $(".RATINGajax").text(data[0]);
                    $count = $(".COUNTajax").text();
		    $sum = $count[0]+data[1]
                    console.log($sum);


                },
                error: function() {}
            });

Here i got a JSON data inside data from response from a Controller. I got the text value in $count. Here $count = 1 user. So I take the integer from here using $count=$count[0]

I have integer data in data[1] I have integer value in $count[0]

Now I want to sum both of these variable. $sum = $count[0]+data[1].

Currently It shows string concatenate value 1+1=11 instead of 2. I want 2.

It needs integer convertion.

Please sign in or create an account to participate in this conversation.