Using Jquery to post single variable
using jquery to post a value to php file but the value is not being posted (COMPANY_NAME). Code below works for multiple values but not when it's changed to post single values? Any tips?
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
var COMPANY_NAME = $( "#COMPANY_NAME" ),
allFields = $( [] ).add( COMPANY_NAME ),
tips = $( ".validateTips" );
$( "#dialog-form5" ).dialog({
autoOpen: false,
height: 200,
width: 350,
modal: true,
buttons: {
"ok": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
if ( bValid ) {
$.post("setCompany.php", {
COMPANY_NAME:$(this).val()
}, function(data) {
if(data=='no')
{ $("#msgbox").fadeTo(200,0.1,function()
{
$(this).html(data).addClass('messageboxerrorAdd').fadeTo(900,1);
});
} else if (data=='wrong') {
$("#msgbox").fadeTo(200,0.1,function()
{
$(this).html("fjdhffh").addClass('messageboxerrorAdd').fadeTo(900,1);
});
} else {
$("#msgbox").fadeTo(200,0.1,function()
{
$(this).html(data).addClass('messageboxerrorAdd').fadeTo(900,1);
});
}
});
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
开发者_如何学编程 }
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
});
Try this :
$.post("setCompany.php",{"COMPANY_NAME":COMPANY_NAME.val()}, function(data)...
JSON objects require keys to be surrounded by double quotes
COMPANY_NAME:$(this).val()
I don't think that $(this) points to the company name field. Try this:
"COMPANY_NAME" : COMPANY_NAME.val()
(as mentioned before, JSON keys need to be in double quotes)
精彩评论