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:
- $( "#cboRequest" ).change(function()
- {
- if (!$("#cboRequest").val())
- {
- $("#divPeriod").hide();
- $("#divPurpose").hide();
- return false;
- };
-
- $.ajax({
- type: 'GET',
- url: "get_request_processing_period.php",
- dataType: "json",
- cache: false,
- data: {cboRequest:$(this).find('option:selected').val()},
- beforeSend: function ()
- {
- $("#divPeriod").hide();
- $("#divPeriodLoading").show();
-
- $("#divPurpose").hide();
- $("#divPurposeLoading").show();
- },
- success: function(response)
- {
- $("#lblRequestName").val(response.name);
- $("#lblProcessingPeriod").html(response.days + " working day(s) <font color='#FF0000'>after approval</b>");
- $("#divPurposeList").html(response.purpose);
-
- $("#divPeriodLoading").hide();
- $("#divPurposeLoading").hide();
-
- $("#divProcessingPeriod").show();
- $("#divPurpose").show();
- },
- error: function(jq,status,message)
- {
- alert('A jQuery error has occurred. Status: ' + status + ' - Message: ' + message);
- }
- });
- });
and this is my PHP:
- $request_category = $_GET['cboRequest'];
-
- $mysql_query = $mysql_connection->prepare('CALL sp_get_request_processing_period(:param_request_category)');
- $mysql_query->bindParam(':param_request_category', $request_category, PDO::PARAM_STR);
-
- $mysql_query->execute();
-
- while($mysql_row = $mysql_query->fetch())
- {
- $request_name = $mysql_row["request_category_name"];
- $processing_days = $mysql_row["processing_period_in_days"];
- }
-
- $request_purpose = "";
-
- $mysql_query = $mysql_connection->prepare("CALL sp_populate_request_purpose(:param_request_category)");
- $mysql_query->bindParam(':param_request_category', $request_category, PDO::PARAM_STR);
- $mysql_query->execute();
-
- while($mysql_row = $mysql_query->fetch())
- {
- $request_purpose .= "<option value=" . $mysql_row["request_purpose_id"] . ">" . $mysql_row["request_purpose_title"] . "</option>";
- }
-
- $response = array("name" => $request_name, "days" => $processing_days, "purpose" => $request_purpose);
-
- echo json_encode($response);
Thanks,