Bug Tracker

Modify

Ticket #5154 (closed feature: invalid)

Opened 4 years ago

Last modified 2 years ago

function for using post with load

Reported by: naktinis Owned by:
Priority: low Milestone:
Component: ajax Version: 1.4.3
Keywords: ajaxrewrite Cc: naktinis@…
Blocking: #7195 Blocked by:

Description

In order for load() method to submit data using post method, one needs to pass data object in the following form: {'name1': 'value1', 'name2': ['value2', 'value3']} etc.

However, there is no easy way of getting this object for some form element.

Currently, I have written this function myself, but it would be nice to have it in the official release anyway.

It would be convenient to simply write: $('box').load('path', $('#form').toObject()) or smth.

Change History

comment:1 Changed 3 years ago by rwaldron

  • Priority changed from major to low
  • Status changed from new to closed
  • Resolution set to wontfix

What you want to use is:

$('box').load('path', $('#form').serialize())

This will serialize the form input elements into key=value pairs for posting.

comment:2 Changed 3 years ago by naktinis

Correct me if I'm wrong, but according to documentation "$('box').load('path', $('#form').serialize())" would issue GET command (the question is about issuing POST), because (quoting serialize, and load method documentations):

  1. The .serialize() method creates a text string in standard URL-encoded notation.
  2. The POST method is used if data is provided as an object; otherwise, GET is assumed.

See:  http://api.jquery.com/serialize/ and  http://api.jquery.com/load/

comment:3 Changed 3 years ago by rwaldron

  • Status changed from closed to reopened
  • Version changed from 1.3.2 to 1.4.3
  • Resolution wontfix deleted
  • Milestone changed from 1.4 to 1.5

I guess I didn't realize that it HAD to be a post. In that case, take a look at this:

 http://richardwaldron.com/test-cases/5154.html

comment:4 Changed 3 years ago by snover

  • Status changed from reopened to open
  • Blocking 7195 added

Truly, the behaviour of $.fn.load is in a bizarre class of its own. Rather than providing a mechanism for switching between GET and POST, we should probably just revisit the logic of the method itself to begin with.

comment:5 Changed 2 years ago by rwaldron

  • Keywords ajaxrewrite added

comment:6 in reply to: ↑ description Changed 2 years ago by temp01

Replying to naktinis:

However, there is no easy way of getting this object for some form element.

There is: .serializeArray(). What you want is:

$(..).load('url', $form.serializeArray());

That should do POST and work like the way you want.

Last edited 2 years ago by temp01 (previous) (diff)

comment:7 Changed 2 years ago by john

  • Status changed from open to closed
  • Resolution set to invalid

Closing after temp01's feedback.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.