Проблем с js не записва информацията взета от _POST

bankera1990

Registered
Имам код който е за чат но имам проблем и той е следния.
с това <input type="checkbox" id="private" /> чеквам ако трябва да е лично съобщение към даден потребител писал в чата но проблема е че не ми го записва в таблицата.
.Js
Код:
function loading(element){$(element).html("Зареждане...");};
function smyle(smyle){hidepanel(); var msg = $('#message').val();$('#message').val(msg+smyle);$('#message').focus();};
function msgto(login,privat){ $('#receiver').val(login);hidepanel(); 
if(privat == 1){
$('#private').attr('checked', true);
}else{
$('#private').attr('checked', false);} 
$('#message').focus();};
function chat_list(){$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=list",success: function(html){$('#responce').html(html);}});};
function online_list(){$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=online",success: function(html){$('#whoonline').html(html);}});};
function messageform(){loading('#sendform');$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=sendform",success: 
function(html){$('#sendform').html(html);}});};
function delmsg(id){loading('#sendresponce');$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=del&id="+id,success: 
function(html){$('#sendresponce').html(html);var err = $('#err').val();if(err == '0'){$('#msg'+id).animate({'opacity': '0'},500);}}});};
function sendmsg(){
var privatemsg = $('#private').attr('checked');
privatemsg == true ? privatemsg = 1 : privatemsg = 0;
var receiver   = $('#receiver').val(); 
var msg = $('#message').val();
loading('#sendresponce');$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=send&privatе="+privatemsg+"&receiver="+receiver+"&msg="+msg,success: 
function(html){$('#sendresponce').html(html);var err = $('#err').val();if(err == '0'){$('#message').val('');chat_list();}}});
};
function floatpanel(){if($('#float_menu').length){if($('#float_menu').is('hidden')){$('#float_menu').animate({'opacity': 'show'},300);}else{$('#float_menu').html('зареждане...');$('#float_menu').animate({'opacity': 'hide'},300, 
function(){$('#float_menu').animate({'opacity': 'show'},300);});}}else{$('body').append("<div id='float_menu'>зареждане...</div>");}var posx = parseFloat($('#posx').val()); var posy = parseFloat($('#posy').val());$('#float_menu').css({'left': (posx+15)+'px','top': (posy-10)+'px'});};
function hidepanel(){
$('#float_menu').animate({'opacity': 'hide'},300,
function(){$('#float_menu').html('')});};
function smyles(){floatpanel();
$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=smyles",success: 
function(html){$('#float_menu').html(html);}});};
function useractions(login,id){floatpanel();
$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=useractions&login="+login+"&id="+id,success: 
function(html){$('#float_menu').html(html);}});};
$(document).ready(
function()
{
$(document).mousemove(
function(event){$('#posx').val(event.pageX);
$('#posy').val(event.pageY);});messageform();online_list();chat_list();setInterval(
function(){chat_list();}, 3000);setInterval(
function(){online_list();}, 10000);
})

с това се проверява дали е маркирано
Код:
if(privat == 1){
$('#private').attr('checked', true);
}else{
$('#private').attr('checked', false);}

проблема май идва от тук

Код:
var privatemsg = $('#private').attr('checked');
privatemsg == true ? privatemsg = 1 : privatemsg = 0;

а по този начин подава информация чрез ПОСТ
Код:
var msg = $('#message').val();
loading('#sendresponce');$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=send&privatе="+privatemsg+"&receiver="+receiver+"&msg="+

но privatе="+privatemsg+" е празно винаги как да го оправя да записва от

Код:
if(privat == 1){
$('#private').attr('checked', true);
}else{
$('#private').attr('checked', false);}
 
Коя версия на jQuery използваш?

Код:
As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop() method.

Пробвай така


[js]privatemsg == 'undefined' ? privatemsg = 0 : privatemsg = 1; [/js]
 
не и така не стана имам чувството че
loading('#sendresponce');$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=send&privatе="+privatemsg+"&receiver="+receiver+"&msg="+msg,success:

&privatе="+privatemsg+"
"+privatemsg+" е празен

Код:
&type=send&privatе=&receiver=bankera1990&msg=Текст от чата
а трябва да е така
Код:
&type=send&privatе=1&receiver=bankera1990&msg=Текст от чата
ако е лично и
Код:
&type=send&privatе=0&receiver=bankera1990&msg=Текст от чата
ако е публично
 
да 1 като го направя така
privatemsg == true ? privatemsg = 0 : privatemsg = 1;
alert(privatemsg) е еденица но не съм маркирал да е лично и пак е 1
 
офф оправих се трябвало да бъде по този начин

[js]function sendmsg(){
var privatemsg = $('#private').prop('checked');
var receiver = $('#receiver').val();
var msg = $('#message').val();
privatemsg == true ? privatemsg = 1 : privatemsg = 0;
loading('#sendresponce');$.ajax({cache: false,type: "POST",url: "ajax.php",data: "&type=send&private="+privatemsg+"&receiver="+receiver+"&msg="+msg,success: [/js]

благодаря Ви все пак :)
 

Back
Горе