Cannot send array to php via AJAX?

Well I followed this question, but cannot send array to php it returns me always empty:

JS:

            values = [];
            values['mpsRegnomer'] = $('#mpsRegnomer').val();
            values['mpsMarka'] = $('#mpsMarka').val();
            values['mpsMarkaOther'] = $('#mpsMarkaOther').val();
            values['engineType'] = $('#engineType').val();
            values['seatNumberInput'] = $('#seatNumberInput').val();
            values['carColor'] = $('#carColor').val();
            values['mpsChassiNum'] = $('#mpsChassiNum').val();
            values['mpsModel'] = $('#mpsModel').val();
            values['mpsModelOther'] = $('#mpsModelOther').val();
            values['mpsManufactureDate'] = $('#mpsManufactureDate').val();
            values['mpsfor'] = $('#mpsfor').val();
            values['VehicleType'] = $('#VehicleType').val();
            values['dvigatelInput'] = $('#dvigatelInput').val();
            values['engineMaxPower'] = $('#engineMaxPower').val();
            values['is_automatic'] = $('#is_automatic').val();
            console.log(values);
        $.ajax({
                type: 'POST',
                url: 'assets/clients/services/saveDataMPS.php',
                async: false,
                dataType: "JSON",
                data: {"values": JSON.stringify(values)},
                success:function(response){
                    alert(1);
                }
        });

console.log(values) show me that array is OK.

PHP code:

<?php

var_dump(json_decode($_POST[“values”])); exit;

It returns me always empty, also tried only with var_dump($_POST); same result… Where am I wrong?

Result from console.log(values):


#javascript #php #ajax #jquery

What is GEEK

Buddha Community

Riley Lambert

1548772039

You defined values as an array and therefore when you stringify it, you get an empty array. Define it as an object like values = {}; and it will work.

You don’t use associative arrays in javascript because

If you use named indexes, JavaScript will redefine the array to a standard object. After that, some array methods and properties will produce incorrect results.
Thats’s why you need to define it as object in the beginning.

values = {};
values['mpsRegnomer'] = $('#mpsRegnomer').val();
values['mpsMarka'] = $('#mpsMarka').val();
values['mpsMarkaOther'] = $('#mpsMarkaOther').val();

Here is a working JSFiddle. http://jsfiddle.net/pk97fe0b/

I am Developer

1615040237

PHP jQuery Ajax Post Form Data Example

PHP jquery ajax POST request with MySQL. In this tutorial, you will learn how to create and submit a simple form in PHP using jQuery ajax post request. And how to submit a form data into MySQL database without the whole page refresh or reload. And also you will learn how to show an error message to the user if the user does not fill any form field.

And this tutorial also guide on how to send data to MySQL database using AJAX + jQuery + PHP without reloading the whole page and show a client-side validation error message if it has an error in the form.

PHP jQuery AJAX POST Form Data In Into MySQL DB Example

Just follow the few below steps and easily create and submit ajax form in PHP and MySQL with client-side validation.

  • Create Database And Table
  • Create a Database Connection File
  • Create An Ajax POST Form in PHP
  • Create An Ajax Data Store File

https://www.tutsmake.com/php-jquery-ajax-post-tutorial-example/

#jquery ajax serialize form data example #submit form using ajax in php example #save form data using ajax in php #how to insert form data using ajax in php #php jquery ajax form submit example #jquery ajax and jquery post form submit example with php

I am Developer

1597487472

Country State City Dropdown list in PHP MySQL PHP

Here, i will show you how to populate country state city in dropdown list in php mysql using ajax.

Country State City Dropdown List in PHP using Ajax

You can use the below given steps to retrieve and display country, state and city in dropdown list in PHP MySQL database using jQuery ajax onchange:

  • Step 1: Create Country State City Table
  • Step 2: Insert Data Into Country State City Table
  • Step 3: Create DB Connection PHP File
  • Step 4: Create Html Form For Display Country, State and City Dropdown
  • Step 5: Get States by Selected Country from MySQL Database in Dropdown List using PHP script
  • Step 6: Get Cities by Selected State from MySQL Database in DropDown List using PHP script

https://www.tutsmake.com/country-state-city-database-in-mysql-php-ajax/

#country state city drop down list in php mysql #country state city database in mysql php #country state city drop down list using ajax in php #country state city drop down list using ajax in php demo #country state city drop down list using ajax php example #country state city drop down list in php mysql ajax

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website?

HourlyDeveloper.io has always been an industry leader for companies and business owners looking to hire PHP web developer. By choosing to Hire PHP Developer from our company, you can always expect the best results. Our PHP services and solutions are always flexible which means that no matter the nature of your project, you can always count on us for getting the best PHP expertise.

Consult with our experts: https://bit.ly/3aEGxPy

#hire php developer #php developer #php development company #php development services #php development #php

Janis  Smitham

Janis Smitham

1626852600

Arrays in PHP - PHP for Beginners - PHP Programming

Hi guys, welcome to my PHP course for beginners in 2020.

Do you want to learn PHP from scratch? In this course, I will be going through all the basics of PHP. I will show you how you could use PHP in HTML code, what variables and data types are, all the different type of operators, control structures, user functions and built in functions and what the super globals are and how you could use them.

After learning all the basics topics, I want to focus on databases using MySQL because we will be creating a login system after.

In this episode, I want to focus on how to use arrays in PHP. An array is a type of data that allows us to store multiple elements of similar data type under a single variable.

#php #php programming #beginners #arrays in php

Cannot send array to php via AJAX?

Well I followed this question, but cannot send array to php it returns me always empty:

JS:

            values = [];
            values['mpsRegnomer'] = $('#mpsRegnomer').val();
            values['mpsMarka'] = $('#mpsMarka').val();
            values['mpsMarkaOther'] = $('#mpsMarkaOther').val();
            values['engineType'] = $('#engineType').val();
            values['seatNumberInput'] = $('#seatNumberInput').val();
            values['carColor'] = $('#carColor').val();
            values['mpsChassiNum'] = $('#mpsChassiNum').val();
            values['mpsModel'] = $('#mpsModel').val();
            values['mpsModelOther'] = $('#mpsModelOther').val();
            values['mpsManufactureDate'] = $('#mpsManufactureDate').val();
            values['mpsfor'] = $('#mpsfor').val();
            values['VehicleType'] = $('#VehicleType').val();
            values['dvigatelInput'] = $('#dvigatelInput').val();
            values['engineMaxPower'] = $('#engineMaxPower').val();
            values['is_automatic'] = $('#is_automatic').val();
            console.log(values);
        $.ajax({
                type: 'POST',
                url: 'assets/clients/services/saveDataMPS.php',
                async: false,
                dataType: "JSON",
                data: {"values": JSON.stringify(values)},
                success:function(response){
                    alert(1);
                }
        });

console.log(values) show me that array is OK.

PHP code:

<?php

var_dump(json_decode($_POST[“values”])); exit;

It returns me always empty, also tried only with var_dump($_POST); same result… Where am I wrong?

Result from console.log(values):


#javascript #php #ajax #jquery