How can I check if my response is a string or JSON Object?
<p>I want my response to be in JSON Object. But in some functions it comes as string and I want to parse it. How can I achieve this? This is my function.</p>

<pre><code>function serverRequest(requestDATA, successCallback, errorCallback, hideIndicator, showAlert){
    var METHOD = "POST";
    var serverURL = 'http://istudy.com.pk/api/server.php'; //Path to Server.php
    //var serverURL = 'http://localhost/istudy/server.php'; //Path to Server.php
    var DATA_TYPE = 'json';
    var TIMEOUT = 20000;
    console.log(requestDATA);
    $$.ajax({
        url: serverURL,
        data: requestDATA,
        dataType: DATA_TYPE,
        type: METHOD,
        timeout: TIMEOUT,
        success: function(data){
            successCallback(data, hideIndicator, showAlert);
        },
        error: function(a, b, c){
            errorCallback(a, b, c, hideIndicator, showAlert);
        }
    }); 
}
</code></pre>

<p>And this is my responseText</p>

<pre><code>responseText: "{"status":"success","message":"Your Order has Processed. Please Note this pin &lt;b style=\"background-color:green;\"&gt;osIyKvAp&lt;\/b&gt; and send it to the admin with payment details."}"
</code></pre>

<p><strong>THIS IS MY PHP FUNCTION</strong></p>

<pre><code>function confirm_order($id, $newarray, $cn) {
    $today = date('y-m-d');
    $expiry = date('Y-m-d', strtotime("+30 days"));
    $total_items = 0;
    $total_price = 0;
    foreach ($newarray as $key =&gt; $val) {
        $total_items++;
        foreach ($val as $doc) {
            $total_price = $total_price + $doc-&gt;doc_price;
        }
    }

    $pin = random_string('alnum', 8);

    $sql = "INSERT INTO orders (order_id, order_UserId, order_total_items, order_amount, date_created,order_status,order_pin)
    VALUES ('', '" . $id . "', '" . $total_items . "', '" . $total_price . "', '" . $today . "','0','" . $pin . "')";

    if (mysqli_query($cn, $sql)) {
        $order_id = mysqli_insert_id($cn);

        foreach ($newarray as $key =&gt; $val) {
            $total_docs = 0;
            $total_items++;
            $sep = '|';
            $sub_price = 0;
            $doc_list = '';
            foreach ($val as $doc) {
                $doc_list .= $doc-&gt;doc_id . $sep;
                $sub_price = $sub_price + $doc-&gt;doc_price;
                $total_docs++;
                $sep = '|';
            }

            $sql = "INSERT INTO cart_items (uc_id, uc_user_id, uc_course_id, uc_course_docs_id, uc_course_docs_num,uc_price,uc_order_num,uc_order_status,uc_dateBuy,uc_dateExpire)
            VALUES ('', '" . $id . "', '" . $key . "', '" . $doc_list . "', '" . $total_docs . "','" . $sub_price . "','" . $order_id . "','0','" . $today . "','" . $expiry . "')";

            mysqli_query($cn, $sql);
        }

        $response_array['status'] = 'success';
        $response_array['message'] = 'Your Order has Processed. Please Note this pin &lt;b style="background-color:green;"&gt;' . $pin . '&lt;/b&gt; and send it to the admin with payment details.';
    } else {
        $response_array['status'] = 'error';
        $response_array['message'] = 'An error occurred. Please try again later.';
    }
    echo json_encode($response_array);
}
</code></pre>

<p>Can I place any check to JSON.parse if and only if my response is string?</p>