JQuery not parsing the json_encode's output properly

JQuery not parsing the json_encode's output properly


Hi,

I am trying to populate a SELECT from PHP and JQuery but the output from PHP is adding a backslash to the closing </option> tag and removing the <option> opening tag like this:

Bank Facilities<\/option>
Embassy<\/option>
Government<\/option>


here is my code:

  1. $( "#cboRequest" ).change(function()
  2. {
  3. if (!$("#cboRequest").val())
  4. {
  5. $("#divPeriod").hide();
  6. $("#divPurpose").hide();
  7. return false;
  8. };
  9. $.ajax({
  10. type: 'GET',
  11. url: "get_request_processing_period.php",
  12. dataType: "json",
  13. cache: false,
  14. data: {cboRequest:$(this).find('option:selected').val()},
  15. beforeSend: function ()
  16. {
  17. $("#divPeriod").hide();
  18. $("#divPeriodLoading").show();
  19. $("#divPurpose").hide();
  20. $("#divPurposeLoading").show();
  21. },
  22. success: function(response)
  23. {
  24. $("#lblRequestName").val(response.name);
  25. $("#lblProcessingPeriod").html(response.days + " working day(s) <font color='#FF0000'>after approval</b>");
  26. $("#divPurposeList").html(response.purpose);
  27. $("#divPeriodLoading").hide();
  28. $("#divPurposeLoading").hide();

  29. $("#divProcessingPeriod").show();
  30. $("#divPurpose").show();
  31. },
  32. error: function(jq,status,message)
  33. {
  34. alert('A jQuery error has occurred. Status: ' + status + ' - Message: ' + message);
  35. }
  36. });
  37. });


and this is my PHP:

  1. $request_category = $_GET['cboRequest'];

  2. $mysql_query = $mysql_connection->prepare('CALL sp_get_request_processing_period(:param_request_category)');
  3. $mysql_query->bindParam(':param_request_category', $request_category, PDO::PARAM_STR);

  4. $mysql_query->execute();

  5. while($mysql_row = $mysql_query->fetch())
  6. {
  7. $request_name = $mysql_row["request_category_name"];
  8. $processing_days = $mysql_row["processing_period_in_days"];
  9. }

  10. $request_purpose = "";

  11. $mysql_query = $mysql_connection->prepare("CALL sp_populate_request_purpose(:param_request_category)");
  12. $mysql_query->bindParam(':param_request_category', $request_category, PDO::PARAM_STR);
  13. $mysql_query->execute();

  14. while($mysql_row = $mysql_query->fetch())
  15. {
  16. $request_purpose .= "<option value=" . $mysql_row["request_purpose_id"] . ">" . $mysql_row["request_purpose_title"] . "</option>";
  17. }

  18. $response = array("name" => $request_name, "days" => $processing_days, "purpose" => $request_purpose);
  19. echo json_encode($response);


Thanks,