0

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']);
?>
9
  • It is like you have the add_album but change the index to myData. Commented Jun 11, 2018 at 0:12
  • I don't understand your meaning. What do you mean by index? Commented Jun 11, 2018 at 0:17
  • missing concatenate operator "." Commented Jun 11, 2018 at 0:17
  • Where am I missing the concatenate operator "."? Commented Jun 11, 2018 at 0:19
  • echo myData.'\\'.$_GET['add_album']; , ditto mkdir you should be getting syntax errors, but may not see them Commented Jun 11, 2018 at 0:21

1 Answer 1

1

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

  1. add <input name="mydata" type="hidden"> to your form
  2. instead of

    var div = document.getElementById("hidden_div");
    var myData = div.textContent;
    

    use

    $('#form3 [name=mydata]').val($('#hidden_div').text());
    
  3. send data: $('#form3').serialize()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.