\$\begingroup\$
\$\endgroup\$
function reg(email, pass){
$.ajax({
url: "uman.php",
type: "post",
data:{email: email, password: pass},
success: function(reply){
if (reply == "success"){
$("#signinup").hide();
$("#donesucc").css("display","block");
console.log(reply);
}
if (reply == "duplicate"){
$("#signinup").hide();
$("#donedupe").css("display","block");
}
}
})
}
Anything I should change? The PHP just echos the status of the query and Javascript takes that value and outputs the results through HTML.
200_success
145k22 gold badges190 silver badges478 bronze badges
asked Jan 31, 2014 at 22:00
1 Answer 1
\$\begingroup\$
\$\endgroup\$
What do you think about this?
var Request = {
version: 1.0, //not needed but i like versioning things
xproxy: function(type, url, data, callback, timeout, headers, contentType)
{
if (!timeout || timeout <= 0) { timeout = 15000; }
$.ajax(
{
url: url,
type: type,
data: data,
timeout: timeout,
contentType: contentType,
success:function(data)
{
if (callback != undefined) { callback(data); }
},
error:function(data)
{
if (callback != undefined) { callback(data); }
},
beforeSend: function(xhr)
{
//headers is a list with two items
if(headers)
{
xhr.setRequestHeader('secret-key', headers[0]);
xhr.setRequestHeader('api-key', headers[1]);
}
}
});
}
};
<script type="text/javascript">
var contentType = "applicaiton/json";
var url = "http://api.lastfm.com/get/data/";
var timeout = 1000*5; //five seconds
var requestType = "POST"; //GET, POST, DELETE, PUT
var header = [];
header.push("unique-guid");
header.push("23903820983");
var data = "{\"username\":\"james\"}"; //you should really deserialize this w/ a function
function callback(data)
{
//do logic here
}
Request.xproxy(requestType, url, data, callback, timeout, header, contentType);
</script>
Explore related questions
See similar questions with these tags.
default