2
\$\begingroup\$
 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
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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>
answered Feb 1, 2014 at 0:29
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.