JQuery :: Return Out Of A $.post Function?

May 6, 2009

If I have this:

$.post('/admin/duration', $str, function(data){
var jsonData = eval('(' + data + ')');
return jsonData.TIME;
});

How do I get the return value from the function to use afterwards? I know this must be simple. I'm just not seeing it.

View 1 Replies


ADVERTISEMENT

Jquery :: $.post - Can't Get The Function To Return A Value To The Other Function

Aug 7, 2009

i've got a function which makes a call to the database( via jquery $.post) to check if a username already exists. All the data I get back is fine and both the conditional statment works as intentded. I just can't get the function to return a value to the other function that calls it. Could this be something to do with the scope.

Code:
function checkIfUsername(o)
{
$.post(""+CI_ROOT+"index.php/admin/check_if_username",{
username: username.val()
}, function(data){
if(data.bool == true){
[Code]....

View 4 Replies View Related

Getting Return Value From Post Anonymous Function

Jan 8, 2011

I have been struggling with a form wizard all day. I'm using jquery stepy (form wizard) along with validation plugin. To cut a long story short, my first step is to get MySQL connection from form controls details. On submit ('next' button) a check is made on an empty hidden control ('hid').

rules: {
hid: {
required: function(){
return checkDBData();
},
messages: {
hid:
{required: 'SQL not available'},
...(etc)...

So, if the function checkDBData passes, false should be returned, so that the form can progress to the next step. If the connection details fail, true is returned so that an error msg is posted.

Here's the checkDBData function:
function checkDBData(){
var host = $('#mysql_host').val();
var username = $('#username').val();
var password = $('#password').val();
var dbname = $('#dbname').val();

$.post("install/sqlcheck.php",
{"host": host,"username": username, "password": password, "dbname": dbname},
function(msg){
if(msg.required == false){
return false;
}else{
return true;
}},
"json"
);
}

The return values don't find their way back to the rules. However, if I hard code false and true to the function...
function checkDBData(){
var host = $('#mysql_host').val();
var username = $('#username').val();
var password = $('#password').val();
var dbname = $('#dbname').val();

$.post("install/sqlcheck.php",
{"host": host,"username": username, "password": password, "dbname": dbname},
function(msg){
if(msg.required == false){
return false;
}else{
return true;
}},
"json"
);
return false; //or return true for testing purposes
}
This works. I assume it's due to the asynchronous nature of the ajax call.

View 2 Replies View Related

JQuery :: Parse Post Return Data?

Jul 11, 2010

When I submit a post request in jquery i.e code...

How can I parse the returned data to get a specific element if the returned data is just an html page?

View 2 Replies View Related

JQuery :: Return Query Results From .ajax POST

Aug 24, 2009

Is it possible to return Query results from a jquery $.ajax POST call?It seems as though it will only return one value. What am I missing? [code]

View 1 Replies View Related

JQuery :: Ajax Post Success - Run An External Function Outside The Post

Aug 17, 2010

I want to run an external function outside the post.

This is what I have currently.

On success of the post I want to run the setGrandTotal(); function which will do some calculating for me.

View 1 Replies View Related

JQuery :: Ajax Post - Accessing Return Data / Result Variable

Nov 30, 2010

So I'm currently working on a ASP.NET Webforms site and I've run in to a small problem. On my .cs file I have the following Webmethod

[WebMethod]
public static string IsJobEditable(int jobid){
try{
string isEditable = "false";
JobsBLL jbl = new JobsBLL();
int jobStatusId = jbl.GetJobStatusId(jobid);
//If the jobs is either waiting or being edited it is
okay to edit it
if(jobStatusId ==
Convert.ToInt32(ConstantsUtil.JobStatus.Waiting) || jobStatusId ==
Convert.ToInt32(ConstantsUtil.JobStatus.Edit)){
isEditable = "true";
}return isEditable;
}catch (Exception ex){
throw ex;
}}

This function in this case will ALWAYS return TRUE as a string. On Aspx page I have the following
$(function () {
$.ajax({
type: "POST",
url: "Coordination.aspx/IsJobEditable",
data: "{jobid:" + jobid + "}",
contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (result) {
alert(result);

//This is written out in the alert {"d":"true"}
I want this in a variable as a string so I can do a check on it before I do some other actions. The format is not a String so I cannot split on it to retrieve the "true" part.
},
error: function (err, result) { alert(err); }
});});

As you can see in the comments the value I get back in the Callback method is in to me a weird format. The type is unknown and I need this value to be able to proceed with my entire method surrounding the small portion of the Javascript. Where to access the result variable / data as a var or anything else that will let me put it into a var (as a string).

View 1 Replies View Related

JQuery :: Success - Error - Small Data Entry Screen - Post Form Data To A Page And Return A Message

Jul 22, 2011

I am writing a small data entry screen that will post the form data to a page and return a message. But i cannot get the Success or Error functions working properly.

Here's the code where strData is the posted querystring of:

I'm not sure whether it should be in a form and using the onsubmit or click of a button.

View 2 Replies View Related

JQuery :: Getting A Return From .ajax Function?

Nov 14, 2011

I'm trying to make a call to .ajax and as a result set a value in a hash (for another call to jquery-ui)

I get the data coming back fine, could put in in a text field in html but not the hash where I want it.

Here below are the parts of my code that I'm using

//setting up datepicker
$(courseStartDateHtmlId).datepicker({
.....
defaultDate : ($(courseStartDateHtmlId).val() != "") ?

[Code].....

I thought that the value of startDate would end up as the defaultDate param for datepicker. No luck. Only an obscure little message in firebug console: "missing: before statement"

View 3 Replies View Related

JQuery :: Return A Second Value From Autocomplete Function?

Jun 3, 2010

as I can return a second value of the autocomplete function?

the script

<script type="text/javascript">
$("#nombre").autocomplete("<?php echo base_url()?>transportistas_controller/autocomplete_partidos");
$("#nombre").blur(function(){

[Code]....

View 1 Replies View Related

JQuery :: Get A Return Value In A Function For A Dynamic Div?

Apr 1, 2011

I wonder how I can get a return value from a JavaScript function to a jQuery function. I have dynamic divs that creates each time I push a button and I want to retrieve the new div ID in my jQuery function sow I can get my date pick to drop down.

javascript function to retrieve the new div ID
function currentCustomerDivName()
{

[code]....

View 2 Replies View Related

JQuery :: Using Return In Callback Function

Sep 30, 2010

I have some problem using the $.post function. I wrote a function that test if a username is already used in my database. That function must return true if the username is free and false in the other case. My problem is that I use the $.post function and I put the return true; and return false; in the callback function. So it's the callback function that returns true/false instead of my function !

Here is my code :
function validateName(){
$.post("ajax_is_name_used.php",
{name: $form_name.val()}, function(data) {
if (data.success == 1) {
$form_name.addClass("error");
return false; // Problem, we are in the callback function !
} else {
return true; // Problem, we are in the callback function !
}}, "json");}

View 4 Replies View Related

JQuery - Get Function To Return An Array?

Nov 14, 2011

How do I get this function to return an array? It seems that outside function(xml) the array is not seen and at the same time return inside function(xml) does not make the GetNumbers function return anything either.

Code:

function GetNumbers(db_id){
$.post("get_numbers.php",{
id: db_id,

[code].....

View 7 Replies View Related

JQuery :: Cycle Plugin StartingSlide Set By A Function Return?

Feb 13, 2011

i have a unusual cycle on my page and it loads slides from url and after arrange and sorted for slide all i need is startingSlide property to accept function return

like this

startingSlide:test();
function test(){
return 0;
}

i look into jquery cycle and it was accept that parameter using parseInt() parseInt() cannot show very well with function returns also like thisparseInt(test());got NaN

View 2 Replies View Related

JQuery :: LoadImage - Function Not Return Valid Object

Jan 10, 2011

I'm writing a function that substantially load a given image making a fadeout/faidin waiting 'till the complete load. The function is named "loadImage" and I would like use it in the following way:
$('#image img').fadeOut().loadImage(src).attr("src",src).fadeIn();

In order to make the image disappear, load... change the attribute "src" of the image and then re-appear. The code for the function is:
(function($) {
$.fn.loadImage = function(src) {
var img = new Image();
$(img).attr('src', src).load(function() {
return this;
});
}})(jQuery);

But when I run it I get the following error:
$("#image img").fadeOut().loadImage(src) is undefined
I think that the function don't return a "valid" object to make it chainable, isn't it?

View 5 Replies View Related

Jquery :: Trying To Add Function To $Post

Mar 29, 2010

I know that there can be a 3rd argument for Jquery's $post. I want to figure out what the best solution is, for a function, that can be used so we can guarantee that no other jquery functions run until the $post action is completed. I use $post to hit 'vote.php' to submit a vote but I want it to complete this process, and be able to confirm it (Without an annoying alert) so it can properly continue with the process of displaying vote results to the site visitor. I just am not sure what I should do. What is the best idea, just create a function that displays a 'please wait' image that loads for a few seconds and then continue?

View 10 Replies View Related

JQuery :: Create A Global Function And Store The Return Value In A Variable?

May 15, 2011

I tried creating a global function to calculate the distance between 2 points.

jQuery.distance(p1, p2){
var dx = p2.x - p1.x;
var dy = p2.y - p1.y;
return Math.sqrt(dx^2 + dy^2);
};

Somewhere else within my code, I declare a new variable in order to store the value returned by the distance function.

var distance = $.distance(particle1, particle2);

However this is not working.

View 3 Replies View Related

JQuery :: Use The Return Value From A Nested Ajax Function As The Value For A Variable In Its Parent?

Jul 17, 2009

I am attempting to use the return value from a nested ajax function as the value for a variable in its parent. However, despite being able to successfully assign the variable within the nested function, it reverts back to its original value after the child function has terminated. Below is the code:

[Code]...

View 3 Replies View Related

JQuery :: $ Function Not Available After HTTP POST

Sep 21, 2011

I have an HTML div that gets filled with the following HTML/javascript code via ajax:

<script
type
=
"text/javascript"

[Code]....

The idea is that when I post the form the response gets loaded back into the same div. This works, but when I use the form to post a file I see the following output from Firebug: $ is not defined

Naturally when I resubmit my form again (for example after incorrect input) the resulting response doesn't get loaded into the div because jquery never setup the ajaxForm method.

View 1 Replies View Related

JQuery :: Using A Load Function With A Post?

Jul 24, 2009

I am unsure as to how to make this work.

var params = $('form#createAdjForm').serialize();
var url = "<?= $this->url(array('controller'=>'create-adjustment',
'action'=>'index'))?>";

[code]....

View 1 Replies View Related

Call Function Only If Another Function Does Not Return Error?

Feb 14, 2011

I'm trying to "progressively enhance" one of my surveys using javascript. Basically, I have rating scales that make use of radio buttons as each point on the scale. Each radio button occupies its own cell in a table. I wrote some functions that will highlight cells on mouseover in a color corresponding to its position on the scale (e.g. the lowest point is red, the midpoint is yellow, the highest point is green). When a radio button is clicked, the background of the button's cell and preceding cells in the same row will be colored accordingly. The functions are working well in FireFox and Chrome (I just have to add a few lines using the addEvent function to make it compatible with IE).

The effect looks a lot nicer when I add a function that makes the visibility of the radio buttons hidden.

However, I want to make sure that there is a fallback option in case the functions that color the cells don't work for whatever reason. I would not want the radio buttons hidden in this case.

Is there a method whereby I can call the "hideRadiobuttons" function only if the other functions are successfully executed?

View 8 Replies View Related

JQuery :: Cannot Get Contents Of Post (function) To Work With IE6 / IE7

Aug 15, 2011

The post is submitted and returns correctly (confirmed by firebug lite), however the code inside the nested function fails to execute on both IE6 and IE7. Works fine on IE8, everything else.
$ (
"form.add"
).
submit (
function
() {
//code outside of .post function executes successfully
$
.post .....

View 8 Replies View Related

JQuery :: Function(data) Not Being Executed After $.post

Mar 22, 2010

I am new to all this but making good progress and having fun in the process. I have written quite a bit over recent weeks (including a few $.post / $.ajax calls) for various sites/applications but this one is really puzzling me. Here is a snippet of code that is causing me problems.

[Code]....

The problem is that execution jumps from line 2 to line 6 ... ignoring the function(data) and I am not sure why. I get the correct value of "team" arriving at the perl script .... and the perl writes the correct json back. I just can't think where else I need to look to debug this - as I said, I have done something similar 5-6 times over the last few weeks - all without a problem. So I am sure I am doing something stupid here.

View 3 Replies View Related

JQuery :: Get Ajax Function To Post Url Parameters

Jul 27, 2011

I have two forms: register and contact, with action attribute that looks like this:

REGISTER.PHP AND CONTACT.PHP FORMS

<form id="myform" action="submit.php?url=register">

and

<form id="myform" action="submit.php?url=contact">

I would like the jquery ajax function to redirect to the above url parameters so that the forms can get processed in their individual functions.

The SUBMIT.PHP page looks like this:

$url = '';
if (isset($_GET['url'])){
$url = strip_tags($_GET['url']);}
if($url=='register'){

[Code].....

View 2 Replies View Related

JQuery :: Passing A Variable From A Post Callback Function?

Oct 23, 2010

I can't seem to get a variable declared from within a post callback, so that I could manipulate my script accordingly. I have delete.php, that deletes an id from a mysql db. If it fails, I want the script to stop and display the error. The .php script echos an "ok" if everything went fine, if not - it echos the error.var abort_error; // set the error variable

$.get("delete.php", { delete: $(this).parent().parent().parent().attr('id') },
function(data){
if(data != 'ok') {

[code]...

View 1 Replies View Related

JQuery :: $('#mydiv').css('margin-left') Return 0px (must Return Auto)

Jun 3, 2010

All is on the title, sorry for my english, i'm french :) I have an html page with style

<style>
#mydiv {
margin-left:auto;
margin-right:auto;
width:250px;
}
</style>

with jquery, i try to get the margin-left ($('#mydiv').css('margin-left'), but the function return 0px, unable to retrieve the good value (auto) anyone has idea to retrieve the value "auto" when margin-left is "auto" ?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved