0

I have a jQuery dialog button, and inside it I parse all the inputs.

I want to send these parsed values to a php file, but when I click "OK" nothing happens -at all-, without any errors.

Here's my code:

$("#dialog").dialog({
            autoOpen: false,
            width: 'auto',
            buttons: [ {
                text: "Ok",
                click: function() {
                    var functionName = $("#txtFunctionName").val();
                    var cassName = $("#txtClassName").val();
                    var classDesc = $("#txtClassDesc").val();
                    var input = $("#txtInput").val();
                    var output = $("#txtOutput").val();


                    /* SEND THE DATA TO addFunc.php */
                    var $dataStr = {'name': functionName,
                                     'input': input,
                                     'output': output,
                                     'class': cassName,
                                     'desc': classDesc};
                    $.post('../php/addFunc.php', 
                                     $data,
                                     function(response){
                                         alert("test");
                                         }

                                     );


                    $( this ).dialog( "close" ); 
                    } 
                }]  
        });

And the addFunc.php contains just a sample echo to verify correctness, but it doesn't alert anything, meaning it didn't work:

<?php
echo "Welcome";
?>
11
  • addFunc.php? Is that a typo? Commented Dec 6, 2014 at 22:58
  • 2
    Also, you're sending $data to the php and not $dataStr, which $data is not set. Commented Dec 6, 2014 at 23:00
  • No, not a typo, only a typo here and not in the actual code/filename. Commented Dec 6, 2014 at 23:01
  • Changed $data to $dataStr, it still does nothing! Commented Dec 6, 2014 at 23:02
  • get rid of the single quotes in the identifiers for the array $dataStr Commented Dec 6, 2014 at 23:03

1 Answer 1

1

Change $dataStr to dataStr and add the correct var (dataStr no $data) in the post function.

Try this:

$("#dialog").dialog({
            autoOpen: false,
            width: 'auto',
            buttons: [ {
                text: "Ok",
                click: function() {
                    var functionName = $("#txtFunctionName").val();
                    var cassName = $("#txtClassName").val();
                    var classDesc = $("#txtClassDesc").val();
                    var input = $("#txtInput").val();
                    var output = $("#txtOutput").val();


                    /* SEND THE DATA TO addFunc.php */
                    var dataStr = {'name': functionName,
                                     'input': input,
                                     'output': output,
                                     'class': cassName,
                                     'desc': classDesc};
                    $.post('../php/addFunc.php', 
                                     dataStr,
                                     function(response){
                                         alert("test");
                                         }

                                     );


                    $( this ).dialog( "close" ); 
                    } 
                }]  
        });
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.