views:

266

answers:

2

I am using :

function AuthenticateUser(alias, password) {
        //$(document).unbind('keypress');
        $("#Login").unbind("click");
        $.getJSON(RPC_URL + "?c=User&password=" + urlencode(password) + "&alias=" + alias + "&m=login&jsoncallback=?", function(data){
             CheckAuthentication(data,alias,password);
        });

    }

Right now...

But instead of that, I want to use POST, instead of GET. I tried $.postJSON and $.post instead of $.getJSON here, but when i use postJSON or post, for some reason my data is not even sent. I saw that in my Temper data. Nothing happened in Temper Data.

Someone told me that this might be a cross domain issue. Because I am sending send data from my virtual.cloudbeta.com to virtual.app.cloud.com.

What should I do here.

I want to have a simple fix on this. I can not keep the data on one server or have a proxy server. One of my friend suggested me to see this : http://alvinabad.wordpress.com/2009/02/13/feb13/

But i could not get how I can use it my issue.

Plz, it would really nice to get some help on this.

Regards Zeeshan

A: 

use jQuery.ajax() instead and specifiy dataType as json and type as POST

see... JQUERY Ref

As far as the cross domain issue your best bet would be to get them all on the same domain (they can be different sub domains) and set document.domain = "cloud.com";

Can you set them up like this? betavirtual.cloud.com and virtual.cloud.com

ctrlShiftBryan
No I can not have the same domain!!!
Zeeshan Rang
+1  A: 

The proper syntax is to use .post and change the return type (4th param) to "json" as per the docs for .post:

var postData = { c: "User",
                 password: password,
                 alias: alias,
                 m: "login" };
$.post(RPC_URL, postData, function (data) {
    CheckAuthentication(data,alias,password);
}, "json");

Not quote sure the post data is how you want it formatted, but I hope you get the idea.

As for cross-domain I don't know if there is a way around it when you're going across domains. Subdomains are ok, but domains might be blocked.

Although really keep in mind putting it in the post isn't going to help your security. Anyone with firebug can see the post data. If you're worried about security encrypt the password (hash) before sending it. If a GET works for you use that, don't just switch to POST, it isn't buying you anything (unless of course you're using SSL for the POST, then it'd be more secure).

Parrots
I will be using SSL too... thanks
Zeeshan Rang
@Zeeshan the method presented by Parrots will work over SSL as well, provided the page the code is running on is also sent over SSL.
Doug Neiner
But still i am facing some problem.. If you see my code, I have a "jsoncallback=?" in the end or my url. but i am trying to do the same thing in my post like jsoncallback = ? also tried jsoncallback = "?" ... then my entire function does not works. except of jsoncallback it works. what should I do ??
Zeeshan Rang
I would recommend not passing the JSONCallback in through post, I think it was intended to allow your back-end code to dynamically know what to call. I'd just have a loging function in your php that you post to that does an ajax call to the other server.
Parrots