I have a form that has data that is parsed to a PHP file. I was wondering how to use the data that is also sent in the variable myData
. If the form serializes then I can use the $_GET['add_album']
, but how do I use myData
in PHP? I want to echo the data in my PHP file. Here is my AJAX:
var div = document.getElementById("hidden_div");
var myData = div.textContent;
/*var pathh = '<?php echo $pathh ?>';*/
alert(JavaScriptAlert);
$.ajax
(
{
url:"add_album.php",
type: "GET",
data: {myData: myData, form: $('#form3').serialize()},
success:function(result)
{
alert(result);
}
}
);
and my PHP:
<?php
echo myData.'\\'$_GET['add_album']; //need to echo out the data inside the "myData" variable
mkdir(myData.'\\'$_GET['add_album']);
?>
data
"is converted to a query string, if not already a string."
Usually, to send form data, you'd use data: $('#form3').serialize()
. You have {myData: myData, form: $('#form3').serialize()}
though, which gets converted to
myData=some_divtext&form=serialized_form_content
Which means on the server, you now have $_GET['myData']
and $_GET['form']
I don't think that's what you want, mostly because you'd have to manually parse the form query string, therefore my suggestion would be
<input name="mydata" type="hidden">
to your forminstead of
var div = document.getElementById("hidden_div");
var myData = div.textContent;
use
$('#form3 [name=mydata]').val($('#hidden_div').text());
data: $('#form3').serialize()