@JellybeanGames It's not just so that he can call PHP code without loading the page. That is secondary to the issue. If he were to use standard, synchronous code (say from an HTML form), then there would be no opportunity to send JSON because everything would be sent in the form of URL encoded key/value pairs in the body of the HTTP request. The actual XmlHttpRequest object in JavaScript can do both synchronous and asynchronous HTTP requests. Moreover, it allows you to set the media type value for the all important HTTP Content-Type header. By default, PHP does not see the application/json media type (in the Content-Type header) and $_POST will not contain any data. Just because the $.ajax method takes a object parameter of dataType: json, does not mean jQuery is actually sending JSON to PHP as it should be (with the correct media type in the Conent-Type header). Unless PHP 7 has been updated to see the application/json mediat type, I suspect that jQuery is fudging it here, perhaps converting to URL encoded key/value pairs, as it is well documented that php://input stream wrapper is required to get data sent via the HTTP POST request method that is not also sent with the following Content-Types: application x-www-form-urlencoded or multipart/form-data.
Just because the $.ajax method takes a object parameter of dataType: json, does not mean jQuery is actually sending JSON to PHP as it should be (with the correct media type in the Conent-Type header). Unless PHP 7 has been updated to see the application/json media type, I suspect that jQuery is fudging it here, perhaps converting to URL encoded key/value pairs, as it is well documented that the php://input stream wrapper is required to get data sent via an HTTP POST request method, that is not also sent with the following Content-Types: application x-www-form-urlencoded or multipart/form-data.
The dataType: json property and value of the settings object does not tell jQuery what data format it should send to the server. It merely tells jQuery what kind of data to expect in response! This example is not actually sending JSON to PHP. Read the jQuery API. $.ajax() is converting JSON to URL encoded key/value pairs. If you want to actually send true JSON with $.ajax(), then you should set the contentType: property of the setting / parameter object to 'applicaton/json'. Additionally, you MUST set processData: to false. Relying on jQuery seems less and less like a good idea for web developers to use.
As you can see on 5:12 Alex has a form with the action "add.php". If he wouldnt return "false" and would press the button the browser would open up "add.php" and send the input information. But as we dont want to load a new page, he catches the action and loading the data in the background via ajax.
how do you json_encode a URL? I am having problems with the backslash. If I encode this to json " echo json_encode("foo//bar) " I get this "foo\/\/bar" in json. How do I escape the // so it encodes correctly to json? thanks and I love your tutorials. Jon
what if i want to send ajax code thathas json string to php file so i can convert it there into php array how can i do that while i tried but failed many times
The MIME type of JSON should be application/json - However if you provide a callback (also known as JSON-P) you use the MIME type of text/javascript, because it's a javascript function that is returned instead of an object.
I tried using the new .done instead of success and nothing works. my echo from 9:55 is showing in the loaded page at the top which doesn't happen in the example for some reason and my console is empty even though i'm doing a console.log(data); inside the done anonymous function.
Alex, its time for an introduction to Web-sockets, I and others with me are thinking of using Web-sockets for Chat application and other social plugins. It would be great if you do a tutorial on this, Or a simple installation and setup guide would be enough too...TY
Hey Alex, nice video. I was watching this as a reference and I noticed that you are using the the 'success' method for success, but that has now been replaced with the 'done' function since jQuery 1.8; So I think you should update the video so that beginners might not experience problems.
How is it possible to encode Hebrew? I was trying to pass php arrays into JavaScript arrays by json_encode. At first it worked but later stopped and showed error. I don’t know why. The Hebrew letters were translated into a series of numbers and letters in the beginning.
Please do a proper php socket tutorial. For example how to make a simple live chat using sockets. Its hard to find a good and easy to understand tutorial
hello dear developer, good evening. Want to work with Json - i i want to translate the following overopass-turbo request [out:csv(::id,::type,"name","addr:postcode","addr:city","addr:street","addr:housenumber","website"," contact:email=*")][timeout:600]; {{geocodeArea:Schweiz}}->.a; ( node(area.a)[amenity=hospital]; way(area.a)[amenity=hospital]; rel(area.a)[amenity=hospital];); out;
Well, of course i would need some JS for that, but still, mainly using sockets and socket servers. Just some tutorial that has a good explanation. ruclips.net/video/69OXnmbAaLI/видео.html
Really good example and the narrator has a good understand on how JSON works with PHP.
so json stands for javascript object ........(searching ....) notation haha
i am about to say this...🤣
When the title says JSON and PHP. Where did Ajex came from? :/
So he can call in PhP code without having to reload the page.
@@ahamuffin4747 Stop being mean. People are here to learn.
@JellybeanGames It's not just so that he can call PHP code without loading the page. That is secondary to the issue. If he were to use standard, synchronous code (say from an HTML form), then there would be no opportunity to send JSON because everything would be sent in the form of URL encoded key/value pairs in the body of the HTTP request. The actual XmlHttpRequest object in JavaScript can do both synchronous and asynchronous HTTP requests. Moreover, it allows you to set the media type value for the all important HTTP Content-Type header. By default, PHP does not see the application/json media type (in the Content-Type header) and $_POST will not contain any data. Just because the $.ajax method takes a object parameter of dataType: json, does not mean jQuery is actually sending JSON to PHP as it should be (with the correct media type in the Conent-Type header). Unless PHP 7 has been updated to see the application/json mediat type, I suspect that jQuery is fudging it here, perhaps converting to URL encoded key/value pairs, as it is well documented that php://input stream wrapper is required to get data sent via the HTTP POST request method that is not also sent with the following Content-Types: application x-www-form-urlencoded or multipart/form-data.
Just because the $.ajax method takes a object parameter of dataType: json, does not mean jQuery is actually sending JSON to PHP as it should be (with the correct media type in the Conent-Type header). Unless PHP 7 has been updated to see the application/json media type, I suspect that jQuery is fudging it here, perhaps converting to URL encoded key/value pairs, as it is well documented that the php://input stream wrapper is required to get data sent via an HTTP POST request method, that is not also sent with the following Content-Types: application x-www-form-urlencoded or multipart/form-data.
The dataType: json property and value of the settings object does not tell jQuery what data format it should send to the server. It merely tells jQuery what kind of data to expect in response! This example is not actually sending JSON to PHP. Read the jQuery API. $.ajax() is converting JSON to URL encoded key/value pairs. If you want to actually send true JSON with $.ajax(), then you should set the contentType: property of the setting / parameter object to 'applicaton/json'. Additionally, you MUST set processData: to false. Relying on jQuery seems less and less like a good idea for web developers to use.
Any reason why console.log() wouldn't work where alert() is? I get the alert working, but nothing is logged in the console (using firefox).
As you can see on 5:12 Alex has a form with the action "add.php". If he wouldnt return "false" and would press the button the browser would open up "add.php" and send the input information. But as we dont want to load a new page, he catches the action and loading the data in the background via ajax.
Yes, good idea so you can understand the possibilities witj JSON and PHP
Very well-spoken and clear tutorial. Thanks phpacademy!
wow amazing! you were able to make me understand JSON with PHP! very very good tutorial, subscribed!
I know it is kind of randomly asking but do anyone know of a good website to watch new tv shows online ?
@Reed Jose flixportal :)
@Deandre Kylo Thank you, signed up and it seems like a nice service :D I really appreciate it !
@Reed Jose you are welcome xD
how do you json_encode a URL? I am having problems with the backslash. If I encode this to json " echo json_encode("foo//bar) " I get this "foo\/\/bar" in json. How do I escape the // so it encodes correctly to json? thanks and I love your tutorials. Jon
what if i want to send ajax code thathas json string to php file so i can convert it there into php array how can i do that while i tried but failed many times
that's a good idea, Alex rocks explaining! I can say he has been my sensei (even thou he doesn't know)
its 2018, still amazing lecture.
The MIME type of JSON should be application/json - However if you provide a callback (also known as JSON-P) you use the MIME type of text/javascript, because it's a javascript function that is returned instead of an object.
It would be much better to handle only reading Json file. Thank you
Awesome to see Firefox back again :)
I tried using the new .done instead of success and nothing works. my echo from 9:55 is showing in the loaded page at the top which doesn't happen in the example for some reason and my console is empty even though i'm doing a console.log(data); inside the done anonymous function.
ALEX IS THE KING OF TEACHERS IN RUclips
Thank you very much!
I actually found out a few hours later, but thank you anyway :)
good and simple tutorial easy to understand !! super like (y) now i can understand where json usefull in after searching a while thanks bro
Alex, its time for an introduction to Web-sockets, I and others with me are thinking of using Web-sockets for Chat application and other social plugins. It would be great if you do a tutorial on this, Or a simple installation and setup guide would be enough too...TY
Hey Alex, nice video. I was watching this as a reference and I noticed that you are using the the 'success' method for success, but that has now been replaced with the 'done' function since jQuery 1.8; So I think you should update the video so that beginners might not experience problems.
How is it possible to encode Hebrew?
I was trying to pass php arrays into JavaScript arrays by json_encode. At first it worked but later stopped and showed error. I don’t know why. The Hebrew letters were translated into a series of numbers and letters in the beginning.
For reason my global.js isn't being picked up and the ajax isn't working even though I referenced it in the index.php
Thanks :) Learned a lot from this
How would you go about displaying the submission onto the index.php page?
again a useful video !
Thanks !
I love this tutorial!
How do I receive an Array Json objects sent from Javascript?
really good tutorial, thanks!
exellent example!
great tut, thanks!
Please do a proper php socket tutorial. For example how to make a simple live chat using sockets. Its hard to find a good and easy to understand tutorial
hi .. why you need to return false on global.js around 6 - 8 mins. thanks
plz help geoserver published layer throw php view the layer code json
Tip: If you have a 64 bit OS, use Waterfox
Hi, I have a question about header. I've seen people using content-type application/json . Is there really any difference?
good , thank lot
03:04 - what does it mean?
Thanks :)
Stopped using google chrome?
Must i use ajax ? or i can i just use $.getJSON() ?
+Mohamed El Mahdy You surely can ))
What is that text program called?
It's Awesome
Sublime text
Хороший урок.
hello dear developer, good evening. Want to work with Json - i
i want to translate the following overopass-turbo request
[out:csv(::id,::type,"name","addr:postcode","addr:city","addr:street","addr:housenumber","website","
contact:email=*")][timeout:600];
{{geocodeArea:Schweiz}}->.a;
( node(area.a)[amenity=hospital];
way(area.a)[amenity=hospital];
rel(area.a)[amenity=hospital];);
out;
Alex I love you :-) ( not in the gay way !)
me too (in the same way) 😂
but only when he does FREE tutorials!!!
Javascript Object.....
..............
Notation
Well, of course i would need some JS for that, but still, mainly using sockets and socket servers. Just some tutorial that has a good explanation. ruclips.net/video/69OXnmbAaLI/видео.html
(Y)
javascript object ... .... notation
LOL