jQuery: The Write Less, Do More JavaScript Library

jQuery ajaxSubmit(), how to send the form in a json format?

View: New views
4 Messages — Rating Filter:   Alert me  

jQuery ajaxSubmit(), how to send the form in a json format?

by DaNieL..! :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi guys, i just leanerd the existence of the ajaxSubmit jQuery plugin,
im wondering if there is a way to use the JSON both to send and
retrieve the requests.

I mean, no the plugin have the option 'dataType', that is used to
specify the format that the server will send back, but i need to send
the form as jquery to the server.

For example, if my form looks like:

<form name="mytest" action="mypage.php" method="get">
<input type="text" name="firstone" id="firstone" value="here some
text!" />
<input type="text" name="secondone" id="secondone" value="text in here
too" />
</form>

i'll love that the plugin will send a request like:

mypage.php?mytest=[{'firstone':'here some text!','secondone':'text in
here too'}]


Is it possible?

Re: jQuery ajaxSubmit(), how to send the form in a json format?

by north-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi, I'm not a 100% sure if that's want you want, but take a look at
(especially the examples):

http://docs.jquery.com/Ajax/jQuery.getJSON

Cheers


On 2 Jul., 14:35, DaNieL <daniele.pigned...@...> wrote:

> Hi guys, i just leanerd the existence of the ajaxSubmit jQuery plugin,
> im wondering if there is a way to use the JSON both to send and
> retrieve the requests.
>
> I mean, no the plugin have the option 'dataType', that is used to
> specify the format that the server will send back, but i need to send
> the form as jquery to the server.
>
> For example, if my form looks like:
>
> <form name="mytest" action="mypage.php" method="get">
> <input type="text" name="firstone" id="firstone" value="here some
> text!" />
> <input type="text" name="secondone" id="secondone" value="text in here
> too" />
> </form>
>
> i'll love that the plugin will send a request like:
>
> mypage.php?mytest=[{'firstone':'here some text!','secondone':'text in
> here too'}]
>
> Is it possible?

Re: jQuery ajaxSubmit(), how to send the form in a json format?

by Giovanni Battista Lenoci-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


DaNieL ha scritto:
> i'll love that the plugin will send a request like:
>
> mypage.php?mytest=[{'firstone':'here some text!','secondone':'text in
> here too'}]
>
>
> Is it possible?
>  
Don't know, but I'm curious, what's the motive behind this choice? If
you pass a json object you have to convert in an array with json_decode
to have an array similar to $_POST, right?




--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482


Re: jQuery ajaxSubmit(), how to send the form in a json format?

by James-279 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm curious what's the reason for that also.

However, if you really need to put into JSON to send over to the
server, you can first use serializeArray()
http://docs.jquery.com/Ajax/serializeArray
to convert all the form data into JSON (object format), and then use
this official JSON script:
http://www.json.org/json2.js
Use the stringify function to convert the JSON into a literal String,
which you can send over to the server.

On Jul 2, 5:22 am, Giovanni Battista Lenoci <gian...@...> wrote:

> DaNieL ha scritto:> i'll love that the plugin will send a request like:
>
> > mypage.php?mytest=[{'firstone':'here some text!','secondone':'text in
> > here too'}]
>
> > Is it possible?
>
> Don't know, but I'm curious, what's the motive behind this choice? If
> you pass a json object you have to convert in an array with json_decode
> to have an array similar to $_POST, right?
>
> --
> gianiaz.net - web solutions
> via piedo, 58 - 23020 tresivio (so) - italy
> +39 347 7196482