0

On click of a #dtDelete button I am opening an ajax modal in bootstrap 3. I am also passing a parameter, selected, along with it and using $_GET on the php page to retrieve it.

As the value of selected may or may not be extremely large I think I should avoid passing the value this way / using $_GET.

How the heck can I pass values other than this method? Due to the nature of opening the modal (loading it then showing it) I am stuck on any other ways.

$('#dtDelete').on('click', function () {
    //open the modal with selected parameter attached
    $('#modal-ajax').load('/modals/m_keystroke_delete.php?selected='+selected);
    $('#modal-ajax').modal('show');                         
});

1 Answer 1

1

Pass a data object as a second param to load for it to make a POST request.

$('#dtDelete').on('click', function () {

    var data = { 'propertyA': 'extremely large data' };

    //open the modal with selected parameter attached
    $('#modal-ajax').load(
      '/modals/m_keystroke_delete.php?selected=' + selected, // url
      data,                                                  // data
      function(responseText, textStatus, XMLHttpRequest) { } // complete callback
    );

    $('#modal-ajax').modal('show');                         
});

You can even pass your "selected" param through the POST request and use $_POST or even $_REQUEST to retrieve the data. Also notice that the modal now shows once the request has completed.

$('#dtDelete').on('click', function () {

    var data = {
      'selected': selected
      'largeData': '...'
    };

    $('#modal-ajax').load(
      '/modals/m_keystroke_delete.php',
      data,
      function() {

        // Invoke the delete-function
        deleteComp();

        // Show the modal
        $(this).modal('show');
      }
    );
});
Sign up to request clarification or add additional context in comments.

3 Comments

I had no idea you could do that. Thank you soo much... you just opened up a lot of possibilities for me. I'm sure it was obvious, but just beginning with all of this I didn't know. Thanks!
One more question... in some cases I was doing something like this $('#modal-ajax').load('/modals/m_keystroke_delete.php?selected='+selected, deleteComp); where I was calling a function at the end. Can I do this with your second method as well and if so how?
The third param is for your callback function. My second example uses an anonymus function. Call your "deleteComp" function within it. Updated my post.

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.