File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes jQuery mobile and JSON post responses Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "jQuery mobile and JSON post responses" Watch "jQuery mobile and JSON post responses" New topic
Author

jQuery mobile and JSON post responses

Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 77
What is the best practice for handling a form post that returns a json response? We are trying to reuse some code in the mobile version of our site which returns JSON and I am unsure of the best way to handle the javascript. I want to populate a dialog.

Thanks,
Rob
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

I'd use $.post() and set the data-type param as "json". This should cause the interpreted JSON data to be passed to the success callback.

If the JSON is not completely well-formed, this will have problems.

Be sure to be using the most up-to-date jQuery as some earlier versions had problems with JSON conversion.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 77
Keep in mind that by default jQuery Mobile is performing ajax form submissions. Are you saying that the best practice here is to bypass jQuery Mobile's default mechanism (i.e. set data-ajax="false" in the form tag), intercept the submit and do my own ajax form submission?

Thanks,
Rob
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

Perhaps -- I haven't yet toyed with jQuery Mobile enough to know if there's a built-in way to configure its automatic posts.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: jQuery mobile and JSON post responses
 
Similar Threads
Problem when using commons.HttpClient from webservice
How to call struts application through JSON
Developing apps for iPhone and other smart phones
HTTP post Json
JSP tag logic calling struts action which returns json