joaocc
asked on
Send extra data with ajaxform
I am using the ajaxform plugin, working great, I just need to post a variable, for example:
> var id = 1;
How Can I do that?
My js code:
Php File:
thank you.
> var id = 1;
How Can I do that?
My js code:
$(document).ready(function()
{
var options = {
beforeSend: function()
{
$("#progress").show();
//clear everything
$("#bar").width('0%');
$("#message").html("");
$("#percent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$("#bar").width(percentComplete+'%');
$("#percent").html(percentComplete+'%');
},
success: function()
{
$("#bar").width('100%');
$("#percent").html('100%');
},
complete: function(response)
{
$("#message").html("<font color='green'>"+response.responseText+"</font>");
},
error: function()
{
$("#message").html("<font color='red'> ERROR: unable to upload files</font>");
}
};
$("#myForm").ajaxForm(options);
//need to post an id variable to the php file
});
Php File:
<?php
require 'functions.php';
require 'config.php';
$con = connect($config['DB_HOST'], $config['DB_USERNAME'], $config['DB_PASSWORD'],'maindb');
mysql_query("SET NAMES 'utf8'") OR die(mysql_error());
//GET THE ID VARIABLE FROM JS
//$id = $_POST['id'];
//var_dump($id);
if(isset($_FILES["myfile"]))
{
if ($_FILES["myfile"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$imagename1 = 'customName.';
$pathinfo = pathinfo($_FILES["myfile"]["name"]);
$extension = $pathinfo['extension'];
move_uploaded_file($_FILES["myfile"]["tmp_name"], "../imgs/" . $imagename1 . $extension);
echo "Uploaded File :".$_FILES["myfile"]["name"];
$fullimage = $imagename1.$extension;
echo "<p>".$fullimage."</p>";
//echo "<p>".$id."</p>";
//UPDATE THE DATABASE WITH THE IMAGE NAME UPLOADED
//$sqlupdate = "update images set image='$fullimage' where id='$id'";
//mysql_query($sqlupdate);
}
}
?>
thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Sir. Perfect :)
You are most welcome - thanks for the points.
ASKER
Julian, when u have some time please have a look at this related question:
https://www.experts-exchange.com/questions/28212091/ajaxForm-plugin-dynamic-id.html
Thank you
https://www.experts-exchange.com/questions/28212091/ajaxForm-plugin-dynamic-id.html
Thank you
Open in new window