javascriptphpjqueryajaxinternal-server-error

500 Internal Server Error when passing data with "POST" method in $.ajax


I'm getting 500 internal server error when passing data to a live server via $.ajax({ method: "POST" });

create-estimation.php

    $.ajax({
        url: "storevalues-offer.php",
        method: "POST",
        data: {
            routes: JSON.stringify(routes),
            offerdetails: JSON.stringify(offerdetails),
            quote_no: "SS19-001",
            offer_no: "1",
            mode_transport: "ship",
            place_receipt: "UK",
            rate_validity_from: "2019-08-29",
            rate_validity_to: "2019-09-20",
            place_delivery: "UK",
            service_mode: "OCEAN",
            last_adate: "2019-08-25",
            commodity: "A",
            transit_time: "22 Days",
            method1: "addOff"
        },
        success: function(data) {
            window.location.reload();
        }
    });

    **
    storevalues - offer.php **

        $method = $_POST['method1'];
    // echo $_POST['products'];
    $items = json_decode($_POST['routes'], true);

    $items1 = json_decode($_POST['offerdetails'], true);

Solution

  • Here you're passing method in your ajax it should be type. Now your ajax code looks like this.

    Remove enter code here Line after your url.

    $.ajax({
        url : "storevalues-offer.php",
        type : "POST",
        data : {
            routes: JSON.stringify(routes),
            offerdetails: JSON.stringify(offerdetails),
            quote_no: "SS19-001",
            offer_no: "1",
            mode_transport:"ship",
            place_receipt: "UK",
            rate_validity_from: "2019-08-29",
            rate_validity_to: "2019-09-20",
            place_delivery: "UK",
            service_mode: "OCEAN",
            last_adate: "2019-08-25",
            commodity: "A",
            transit_time: "22 Days",
            method1: "addOff"
        },
        success : function(data){
            window.location.reload();
        }
    });
    

    If you still getting 500 internal error check with inspect element. Go to inspect element >> network >> Response.