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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.