Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:35:14+00:00 2026-05-26T20:35:14+00:00

My objective with this code is when an user click in edit button, is

  • 0

My objective with this code is when an user click in edit button, is sent this all=<?php echo $arr; ?> to the page edit.php .

This code simply does nothing (no ajax call in firebug).

<?php 
$arr = array("one", "two", "three")
?>
    <div id="content">
    <input class="edit" type="submit" value="Edit" /> 
    </div>

    <script type="text/javascript">
    $(document).ready(function () {
        $(".edit").submit(function () {
            $.ajax({
                url: "edit.php",
                type: "post",
                dataType: "html",
                data: "<?php echo json_encode( $arr ); ?>",
                success: function (data) {
                    $('#ad').html(data);
                }
            });
        });
    });

    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:35:14+00:00Added an answer on May 26, 2026 at 8:35 pm

    Edit As @MilanJaric showed, you do need to operate on the click of the submit button. In addition, however, you should prevent the default action of the click as well. End Edit

    You need to echo the data json_encoded and wrapped in quotes:

    <div id="content">
      <input class="edit" type="submit" value="Edit" /> 
    </div>
    
    <script type="text/javascript">
      $( function()
      {
        $( '.edit' ).click( function( e )
        {
          $.ajax( {
            url: 'edit.php;,
            type: 'post',
            dataType: 'html',
            data: '<?php echo json_encode( $arr ); ?>',
            /* It's hard to tell based on your code, but if you wanted a var at the server named "all" use this instead of the above line:
            data: {
              all: '<?php echo json_encode( $arr ); ?>'
            },
            */
            success: function( data )
            {
              $( '#ad' ).html( data );
            }
          } );
    
          e.preventDefault();
        } );
      } );
    </script>
    

    IMO, however, it gets real ugly to echo PHP inside your JS especially if you have to do a lot of it, so when the need arises, I use an IIFE to inject PHP data into the code as a JS var. This allows me to isolate all PHP echoing within the parens of the invocation of the IIFE:

    <?php 
      $arr = array("one", "two", "three")
    ?>
    
    <div id="content">
      <input class="edit" type="submit" value="Edit" /> 
    </div>
    
    <script type="text/javascript">
      ( function( arr )
      {
        $( function()
        {
          $( '.edit' ).click( function( e )
          {
            $.ajax( {
              url: 'edit.php;,
              type: 'post',
              dataType: 'html',
              data: arr,
              /* It's hard to tell based on your code, but if you wanted a var at the server named "all" use this instead of the above line:
              data: {
                all: arr
              },
              */
              success: function( data )
              {
                $( '#ad' ).html( data );
              }
            } );
    
            e.preventDefault();
          } );
        } );
      }(
        '<?php echo json_encode( $arr ); ?>'
      ) );
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code from my style.php script The objective: User should be able
I am new to Objective-C and I have no clue why this code is
I have some Objective-C code that looks like this: #define myVar 10 float f
First of all, I found this: Objective C HTML escape/unescape , but it doesn't
This is the code which I'm working: <TextBlock TextWrapping=Wrap Text={Binding Objective} Grid.Column=0 VerticalAlignment=Center FontWeight=Bold
This is Objective-C, in Xcode for the iPhone. I have a method in main.m:
i don't really know what ruby,gems, or ror is, my objective is make this
This is an objective-c question. I would like to call a method in an
This is an example from The Objective-C 2.0 Programming Language. I was just wondering,
Is this the correct (or even a valid way) to use emums in Objective-C?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.