Jump to content

Best practices for passing data...


ajlisowski

Recommended Posts

Hey everybody, Ive been messing around with ajax for a year or so now. However, one thing I feel like I am always sort of "hacking" together is the way I pass data back to javascript.

 

A lot of times I will simply pass back a string with some custom deliminator (ex: ** or ||) however this does not seem to be the most effecient or "correct" way of doing things. Ive reused a ton of code, so a lot of my projects all run off the same basic handlers which explode the deliminator, check the first result for a success or error code and then handle the rest of the array as data.

 

Is this wrong? Should I switch to using JSON or XML? Or is what I am doing acceptable?

Link to comment
https://forums.phpfreaks.com/topic/201373-best-practices-for-passing-data/
Share on other sites

Why XML would be 'best practice'? Just because it's an 'X' in 'Ajax' ?

 

The argment between proponents of XML and JSON is heated, but I can't really see actual arguments on favor of either. I like JSON more, but that might be because I work with ExtJS mostly, which has some splendid tools for JSON.

Argument from age? Doesn't seem valid for me ;)

 

Anyway, I think the onswer to OP's question is to use some standarised fromat, like XML or JSON or even php serialised data. Which  exactly is the best for given application, depends on specific rquirements for this applicaiton.

For the sake of knowledge I was looking into how to pass an xml object from JS to PHP.

 

I know that you can set your header to txt/xml in the httprequest object before sending it.

 

I monitored my progress in firebug and can see that the POST successfully contains the xml object, but how do I actually access that in the php file?

 

$_REQUEST is empty, which makes sense since I didnt send it as a post param.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.