Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

jQuery mobile and JSON post responses

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps -- I haven't yet toyed with jQuery Mobile enough to know if there's a built-in way to configure its automatic posts.
 
reply
    Bookmark Topic Watch Topic
  • New Topic