---
title: "Jquery AJAX - JSON or TEXT"  
description: "Jquery AJAX - JSON or TEXT"  
author: "Anonymous User"  
published: 2013-06-20  
updated: 2013-06-20  
canonical: https://www.mindstick.com/forum/1255/jquery-ajax-json-or-text  
category: "json"  
tags: ["json"]  
reading_time: 2 minutes  

---

# Jquery AJAX - JSON or TEXT

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs),\
I'm trying to [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) the TEXT from the getsku [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) after submitting but not sure how to really do it. \
**1) How do i retrieve the POST data?****\****2) How do i retrieve and post it back , if i have [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) varaible to pass back ([Datatype](https://www.mindstick.com/forum/160266/explain-the-datatype-data-annotation-and-its-significance-in-data-entry-and-display):text)****\****3) When should i use JSON, and when text.****\****4) If i'm using JSON how do i read it(after javascript) and display it(returned data to javascript).**\
javascript in main page\
[function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) getsku(){\
**$.ajax({** **type: "POST",** **url: "funcAjax.php",** **data: { 'ddl1': $("#drop_1").val(), 'ddl2': $("#tier_two").val() },** **dataType: 'text',** **[success](https://www.mindstick.com/articles/12957/best-tips-to-make-your-ghostwriting-experience-a-success): function(data) {** **$("#sku").val(data);** **},** **complete: function() {** **alert('Complete: Do something.');** **},** **error: function() {** **alert('Error: Do something.');** **}****});****}****\**Button\
**<input type="button" value="Get SKU" [onclick](https://www.mindstick.com/forum/12718/onclick-for-hyperlink)="getsku();" >****\**Trying to retrieve from another php and return a data to the above php(Having [Issues](https://www.mindstick.com/articles/12944/mattresses-for-kids-and-mothers-should-meet-certain-criteria-issues-you-should-consider) here)**\****if(isset($_REQUEST['ddl1'])) {** **echo "FOUND1";****}else{****echo "FOUND2";****}**\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) for any recommendations or solutions.

## Replies

### Reply by AVADHESH PATEL

Always return JSON from your PHP. Then you can include as many variables as you need in your response, and an error code as well if appropriate - like this:\
{"error":"0","result1":"result 1 data","result2":"result 2 data"}Then your success function can become:\
success: function(data) { if (data.error != 0) { // An error occurred on server: do something } else { $("#sku").val(data.result1); // do something with data.result2 }},Your PHP would become something like this:\
if(isset($_REQUEST['ddl1'])) { echo json_encode(array("error"=>0, "result1"=>"FOUND1"));}else{ json_encode(array("error"=>1, "result1"=>"NotFOUND"));}


---

Original Source: https://www.mindstick.com/forum/1255/jquery-ajax-json-or-text

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
