I need to pass the parameters to URL.I have posed the code.
How can I pass the username and password entered in the textbox to URL in my code.thanks for any help..
You should not send password in the URL.
If you want to pass some other details: Update these two lines as below:
data: {data1:$("input#data1").val(),data2:$("input#data2").val()},
url: "http://localhost:53179/hdfcmobile/hdfc.ashx",
if you want to pass a url parameter, the you want to use:
type: 'GET'
and also:
url: 'http://localhost:53179/hdfcmobile/hdfc.ashx
into the .ajax configs, using type:'POST' will post the fields into the headers instead of the url.
Try below code:
You can try your code in this pattern...
var sdate = $('#banners_startdate').val();
var edate = $('#banners_enddate').val();
if(sdate != '' && edate != ''){
$.ajax({
url: 'your url',
data: 'apiname=get_banner_stat_platform_sharing&var=bannerstats&sdate=' + sdate + '&edate=' + edate,
dataType: 'html',
success: function(data){
$('#bannerstats').html(data);
return false;
}
});
}
Where username and password can be fetch by id:
function ajaxcall(username,password)
{
jQuery.ajax({
type: "POST",
url: "Enter Url to pass",
data: {user: username, pass: password},
dataType: "html",
success: function(data) {
//write code what you want to do here
}
});
}
You can fetch the value on page by just $_POST['user'] and $_POST['pass'].
Related
I am writing a thing to compare two passwords with each other, if they match the script sends out a response that says it is the same.
I currently have got this code:
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: "'password1'='" + $("#Password").val() + "', 'password2'='" + $("#repeatPw").val() + "'",
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Now my problem is that i cant get this password1 and password2 in a proper array i can explode in the checkPasswords.php, this posts this:
Array ( ['password1'] => 'fasfasdfasSD2', 'password2'='asdasdasd' )
But this is not a proper array as it only puts password1 in proper array format, how would i go about making password2 in this format too?
Thank you all in advance!
You can do it with a FormData object:
$("#repeatPw").keyup(function(){
var fd = new FormData();
fd.append('password1', $("#Password").val());
fd.append('password2', $("#Password").val());
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: fd,
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Or do it the JSON way:
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data :{
password1: $("#Password").val(),
password2: $("#repeatPw").val(),
},
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Create an array and pass it as the ajax post data,
var data=[];
data['password1']= $("#Password").val();
data['password2']= $("#repeatPw").val();
Though you could do this in the client side itself.
if($("#Password").val().trim() == $("#repeatPw").val().trim())
//password Matches
Hopes this help u..
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data :{
password1: $("#Password").val(),
password2: $("#repeatPw").val(),
},
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Try like this
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: {'password1' : $("#Password").val(), 'password2' : $("#repeatPw").val() },
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
can you help about that issue?
I am trying to pass my data to the controller. Below you can see my ajax code.
<script type="text/javascript">
$(document).on("click", "#login_button", function () {
var userName = document.getElementById("userName").value;
var password = document.getElementById("password").value;
if (userName !== "" && password !== "") {
$.ajax({
url: '/Home/Login',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: {
'userName' : userName,
'password' : password
},
datatype: 'json',
success: function (data) {
}
})
}
else {
alert("Lütfen Alanları Doldurunuz.")
}
})
</script>
And my controller is like,
[HttpPost]
public ActionResult Login(string userName, string password)
{
return View();
}
I checked my data and it is not empty or null. How can I fix it?
Now I am getting this error =
jquery.min.js:4 POST http://localhost:59277/Home/Login 500 (Internal Server Error)
Thanks a lot.
I had the same problem today during a programming competition.
What solved it for me was using a different way of sending a GET request:
$.get("URL/to/send/request/to", function(data, status){
alert("Data: " + data + "\nStatus: " + status);//data is the actual response you get, while status is weather the request was successful
});
});
Hope it works for you too.
i thik you should use
url: 'http://stackoverflow.com/Home/Login',
instead of
Home/Login
i solve my problem changing the type of ajax as "GET" and changing my controller as "HttpGet" but when I do this for "POST" it didn't solve. Can anyone explain it to me?
$.ajax({
url: 'http://stackoverflow.com/Home/Login',
type: "POST",
dataType: 'json',
data: dataToPost,
contentType: "application/json; charset=utf-8",
success: function (data) {
alert("hi" + data);
}
});
i think it is work
I have a PHP function that is supposed to return a JSON object to an AJAX call, but instead it is returning a string. Here is the PHP that I am calling from an AJAX call.
<?php
echo json_encode(array("error", 0, "Success!"));
?>
Here is the AJAX call.
$.ajax({
type: "POST",
url: "../api/login.php",
data: { id: username, password: password },
success: function(response) {
alert( "Data Saved: " + response );
$("#login_username").val("");
$("#login_password").val("");
}
});
When this function returns, I try to access response in the console, and this is what happens
response
> "["error",0,"Success!"]"
response[0]
> "["
If you are expecting an object then specify the dataType:json in the ajax settings. It will also ensure that if there are any invalid JSON being sent from the server, it gets erred out with parse error. Most probably you don't have a content-type (application/json; charset=utf-8) specified in your response header which lets jquery to determine the mime type itself, so specify the dataType ensure that you get an object or an error back(incase of invalid JSON).
$.ajax({
type: "POST",
dataType:'json'
url: "../api/login.php",
data: { id: username, password: password },
success: function(response) {
alert( "Data Saved: " + response );
$("#login_username").val("");
$("#login_password").val("");
}
});
Your implementation appears to be using jQuery, or some mock-up of jQuery. If it is not using jQuery, I will be happy to share more solutions to your problem.
Add dataType
$.ajax({
dataType: 'json',
type: "POST",
url: "../api/login.php",
data: { id: username, password: password },
success: function(response) {
alert( "Data Saved: " + response );
$("#login_username").val("");
$("#login_password").val("");
}
});
The problem is that, by default, jQuery expects a string.
var foo = "bar";
foo[1] === "a"; // true
Documentation: jQuery.ajax
add a param in your ajaxcall
$.ajax({
type: "POST",
url: "../api/login.php",
data: { id: username, password: password },
dataType: "json" //-< add this param.
success: function(response) {
alert( "Data Saved: " + response );
$("#login_username").val("");
$("#login_password").val("");
}
});
http://api.jquery.com/jQuery.post/
I'm building a PhoneGap app where user press button which then sends data to server. On the success handler I have a new function that asks user some questions with prompt box and then sends them back to server. So I need to make the prompt box appear as long as the condition "status=ok" is true.
I don't know how many times the prompt box has to appear, it can be anything from 1 to 10 times, so I guess I need to make a some sort of loop, but how can I do it?
This is the code I've been using now:
function UpdateRecord(update_id)
{ var id = getUrlVars()["id"];
jQuery.ajax({ type: "POST",
url: serviceURL + "update.php",
data: 'id='+id ,
cache: false,
success: function(data) {
console.log(data)
if(data.key[0].status == "ok"){
var reply = prompt(data.key[0].QUESTION, "");
jQuery.ajax({ type: "POST",
url: serviceURL + "question.php",
data: 'id='+id+'&reply='+reply ,
cache: false,
success: function(data) {
window.location = "page.html" }
} else {
window.location = "page.html"
}
}
});
}
I think what your after is moving the response from the AJAX call into a method AskQuestion (or whatever you want to call it). This function would prompt and would query if the answer was correct or not and redirect them to another page:
function AskQuestion(data)
{
var id = getUrlVars()["id"];
console.log(data);
if(data.key[0].status == "ok") {
var reply = prompt(data.key[0].QUESTION, "");
jQuery.ajax({ type: "POST",
url: serviceURL + "question.php",
data: 'id='+id+'&reply='+reply,
cache: false,
success: AskQuestion});
} else {
window.location = "page.html";
}
}
function UpdateRecord(update_id)
{
var id = getUrlVars()["id"];
jQuery.ajax({ type: "POST",
url: serviceURL + "update.php",
data: 'id='+id,
cache: false,
success: AskQuestion});
}
I have already tried it via ajax but it doesn't work so Help me please !!!!!!
And i tried it into cookie but in code behind didnt see it
var datah = $(“#currid”).html()
var data = {
id: currid,
html: datah
};
$.ajax({
type: "POST",
url: url,
data: data,
success: function(msg){
alert( "return back" );
}
});
Try this
You must encode the html content before transmitting . You can use escape in java script for this.And you can decode back it from server
var encodedData= escape($(“#id”).html()) ;
var postData = { htmlData:encodedData};
$.ajax({
type: "POST",
url: url,
data: postData,
success: function(msg){
// do your operation
}
});