I am trying to pass 4 parms on an ajax call with jquery.
Only the first parm works. The other thee do not.
var share_nid = $('.share_class').attr('share_nid');
var share_type = $('.share_class').attr('share_type');
var share_message = $('.share_class').attr('share_message');
$.ajax({
type: "POST",
url: "/sites/default/themes/ajax/ajax_share_content.php",
data: {uid: <?php echo $user->uid ?>,
nid: share_nid,
type: share_type,
message: share_message}
success: (function( msg ) {
alert( "Data Saved: " + msg );
})
or maybe like this...
$.ajax({
type: "POST",
url: "/sites/default/themes/ajax/ajax_share_content.php",
data: {"uid=<?php echo $user->uid ?>&nid="+share_nid+"&type="share_type"&message="share_message,
success: (function( msg ) {
alert( "Data Saved: " + msg );
})
});
.
.
.
.
.
.
edit
This is what worked for me… Is this “safe” from injection. Is using JSON better?
$.ajax({
type: "POST",
url: "/sites/default/themes/ajax/ajax_share_content.php",
data: "uid=<?php echo $user->uid ?>&nid="+share_nid+"&type="+share_type+"&message="+share_message,
success: (function( msg ) {
alert( "Data Saved: " + msg );
}),
});
The code you posted shouldn’t work at all – it contains a syntax error: After
share_message}you need a,. Besides that, there’s no reason to enclose the success function in().By the way, using firebug you can easily find out what’s actually sent (nothing should be sent since the code of the function call is erroneous) and where an error occurs (actually, the latter can be done without FB by simply opening the error console).