O'Reilly Forums: Jsonp Vs. Php? - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Jsonp Vs. Php?

#1 User is offline   Beth Robson 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Employee
  • Posts: 322
  • Joined: 17-September 08
  • Gender:Female
  • Location:Seattle, WA
  • Interests:I am interested in computer science, the Web, social media and the internet, Mac development, and adult learning.

Posted 05 October 2010 - 03:19 PM

Question from chat room: can users use JSONP instead of PHP to serve content to web apps?

Elisabeth Robson
Co-founder, WickedlySmart.com
Author: Head First HTML5 Programming, Head First HTML and CSS, Head First Design Patterns
0

#2 User is offline   edg 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 06-October 10

Posted 06 October 2010 - 06:00 AM

This is an apples to oranges comparison.

PHP is a programming language. JSON is a data format. (http://en.wikipedia.org/wiki/JSON) JSONP is explained in the JSON wiki page and seems to me to be more of a technique, but this still requires a server side technology to return the results.

PHP was a (probably wise) choice for the class, since it's easy to deploy, but it's only to provide a server component that the newly developed apps can talk to.

In practice, the server component, should one be needed, could be written in PHP, Java, Perl, whatever, and could return JSON, JSONP, XML, plain text, or whatever the client (which is the subject of the class) requires and can handle.


0

#3 User is offline   AverageJake 

  • Active Member
  • PipPip
  • Group: O'Reilly Author
  • Posts: 36
  • Joined: 04-October 10
  • Gender:Male
  • Location:Seattle, WA

Posted 06 October 2010 - 04:25 PM

QUOTE (edg @ Oct 6 2010, 07:00 AM) <{POST_SNAPBACK}>
This is an apples to oranges comparison.

PHP is a programming language. JSON is a data format. (http://en.wikipedia.org/wiki/JSON) JSONP is explained in the JSON wiki page and seems to me to be more of a technique, but this still requires a server side technology to return the results.

PHP was a (probably wise) choice for the class, since it's easy to deploy, but it's only to provide a server component that the newly developed apps can talk to.

In practice, the server component, should one be needed, could be written in PHP, Java, Perl, whatever, and could return JSON, JSONP, XML, plain text, or whatever the client (which is the subject of the class) requires and can handle.


Thank's edg for the great answer. Whoever asked this question, please let us know if this does not make sense.

Jake

0

#4 User is offline   jerlin09 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 12-October 10

Posted 19 October 2010 - 10:12 PM

Apache can be used to serve content to web applications.



Web Development Services

This post has been edited by jerlin09: 19 October 2010 - 10:12 PM

0

#5 User is offline   Jireizo 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-November 11

Posted 15 November 2011 - 04:36 AM

Not sure if I'm describing this correctly. At present, how to handle the ajax request is as follows:
An Ajax request is made, for example: / store / car /: ProductID / add to wit:
The product is added to the shopping MySQL users through
The data is returned new car and wrapped in a view in html
Javascript receiving the correct node and updates the page.

What's wrong with this approach? Seems pretty simple and effective. My partner tells me that is considered "old school" I am "2 years of delay" and saying that it is very slow compared to handle JSON leave.

Its methodology, if I understand correctly, it works as follows:
An Ajax request is made, for example: / store / car /: ProductID / add to wit:
The product is added to the shopping MySQL users through
New car data is returned and is encoded in json format
And it seems that JS is doing all the processing of HTML manipulation and data before updating the correct node.

I have little experience with their method, so do not really have an opinion on it that looks like a lot of unnecessary work that PHP can do so fast and with half the code. Does someone recognize or have experience in how to do this?
........................................online thumbnail generator...........................................
0

#6 User is offline   Maggies Daddy 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 27-November 11

Posted 27 November 2011 - 01:07 PM

PHP files are not uploadable on most web servers. Im not sure about the JSONP.





http://www.blairlockout.com

This post has been edited by Maggies Daddy: 27 November 2011 - 01:08 PM

http://www.blairlockout.com
0

#7 User is offline   Velva 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 09-December 11

Posted 14 December 2011 - 03:13 AM

I am facing the origin policy problem, and by researching the subject, I found that the best way for my particular project would be to use JSONP to do cross-origin requests.

I've been reading this article from IBM about JSONP, however I am not 100% clear on what is going on.

All I am asking for here, is a simple jQuery>PHP JSONP request (or whatever the terminology may be ;) ) - something like this (obviously it is incorrect, its just so you can get an idea of what I am trying to achieve :) ):

jQuery:

$.post('http://MySite.com/MyHandler.php',{firstname:'Jeff'},function(res){
alert('Your name is '+res);
});
PHP:

<?php
$fname = $_POST['firstname'];
if($fname=='Jeff')
{
echo 'Jeff Hansen';
}
?>
How would I go about converting this into a proper JSONP request? And if I were to store HTML in the result to be returned, would that work too?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users