Search Results

Search found 70 results on 3 pages for 'beforesend'.

Page 1/3 | 1 2 3  | Next Page >

  • jsonp is not firing beforeSend?

    - by user283357
    Hi All, I am working on a project to call a webservice from different domain using $.ajax with dataType set to jsonp. $.ajax({ type: "GET", url: testService.asmx, async: true, contentType: "application/json; charset=utf-8", dataType: "jsonp", beforeSend: function (XMLHttpRequest) { alert('Before Send'); //Nothing happnes }, success: function (response) { alert('Success'); //this was fired }, complete: function (XMLHttpRequest, textStatus) { alert('After Send'); //this was fired } }); The problem is I have a ...loading animation which I want to display while the web service request is being processed. I tried using "beforeSend:" to show the loading animation but it seems like "beforeSend" is not getting fired. The animation works fine when the app is on the same domain (using jsonp) but when I move the app into a different server, everything works except "beforeSend" is not getting called. So users will not be able to see the loading animation. Is there any workaround for this?

    Read the article

  • jquery ajax request is sent BEFORE beforeSend

    - by Booosh
    Hi all, had anyone the same experiences with jquery ajax() and the beforeSend property??? And even better... any advice how to fix this problem ??? THX ;-) Actually what i am doing is reading from the database with an ajax call before i wanna sent the new data to the database via ajax (I deed to get to the last page of all comments). What happens is that beforeSend retrieves the data WITH the data which should be sent afterwards?!?! Any ideas?!?! $.ajax({ type: 'POST', url: '_php/ajax.php', dataType:"json", async:false, data:{ action : "addComment", comment_author : comment_author_val, comment_content : comment_content_val, comment_parent_id : comment_parent_id_val, comment_post_id : "<?=$_REQUEST["ID"]?>" }, beforeSend: function() { //WHAT A MESS... if (typeof commentOpen == "undefined") { $.get("_php/ajax.php", { action: "getComments", commentPage: '', ID: "<?=$_REQUEST["ID"]?>" }, function(data){ $('#comments > ul').html(data); return true; } ); } },

    Read the article

  • jQuery Ajax (beforeSend and complete) working properly on FireFox but not on IE8 and Chrome

    - by Farhan Zia
    I am using jQuery ajax version 1.4.1 in my MVC application (though the issue I am discussing was same with the old jQuery version 3.2.1) as well, to check during customer registration if the username is already registered. As the user clicks on the "Check Availibility" button, I am showing a busy image in place of the check button (actually hiding the check button and showing the image) while checking the availibility on the server and then displaying a message. It is a Sync call (async: false) and I used beforeSend: and complete: to show and hide the busy image and the check button. This thing is working well on Firefox but in IE 8 and Chrome, neither the busy image appear nor the check button hides rather the check button remained pressed as the whole thing has hanged. The available and not available messages appear correctly though. Below is the code: HTML in a User Control (ascx): (i have replaced the angular braces with square below) [div id="available"]This Username is Available [div id="not_available"]This Username is not available [input id="txtUsername" name="txtUsername" type="text" size="50" /]  [button id="check" name="check" type="button"]Check Availability[/button] [img id="busy" src="/Content/Images/busy.gif" /] On the top of this user control, I am linking an external javascript file that has the following code: $(document).ready(function() { $('img#busy').hide(); $('div#available').hide(); $('div#not_available').hide(); $("button#check").click(function() { var available = checkUsername($("input#txtUsername").val()); if (available == "1") { $("div#available").show(); $("div#not_available").hide(); } else { $("div#available").hide(); $("div#not_available").show(); } }); }); function checkUsername(username) { $.ajax({ type: "POST", url: "/SomeController/SomeAction", data: { "id": username }, timeout: 3000, async: false, beforeSend: function() { $("button#check").hide(); $("img#busy").show(); }, complete: function() { $("button#check").show(); $("img#busy").hide(); }, cache: false, success: function(result) { return result; }, error: function(error) { $("img#busy").hide(); $("button#check").show(); alert("Some problems have occured. Please try again later: " + error); } }); }

    Read the article

  • How to group rules in jquery

    - by Daniele
    Hi I've got a simple question. I've this code below, i use ajax three times in very similiar ways the only things that change are the data passed and the id of the target. Is there a way to group these instructions in a simple one? Thx D. $('#fld_email').focusout(function() { var request_email = $(this).val(); $.ajax({type:"GET", url: "autocomplete.asp", data: "fld=firstname&email="+request_email, beforeSend: function(){$('#fld_firstname').addClass('ac_loading');}, success: function(msg){$('#fld_firstname').val(msg);$('#fld_firstname').removeClass('ac_loading'); } }); $.ajax({type:"GET", url: "autocomplete.asp", data: "fld=lastname&email="+request_email, beforeSend: function(){$('#fld_lastname').addClass('ac_loading');}, success: function(msg){$('#fld_lastname').val(msg);$('#fld_lastname').removeClass('ac_loading');} }); $.ajax({type:"GET", url: "autocomplete.asp", data: "fld=phone&email="+request_email, beforeSend: function(){$('#fld_phone').addClass('ac_loading');}, success: function(msg){$('#fld_phone').val(msg);$('#fld_phone').removeClass('ac_loading');} }); } );

    Read the article

  • Weird "406 not acceptable" error

    - by Horace Loeb
    When I try to hit this action via Javascript, I get a 406 Not Acceptable error: def show @annotation = Annotation.find_by_id(params[:id]) respond_to do |format| format.html { if @annotation.blank? redirect_to root_path else redirect_to inline_annotation_path(@annotation) end } format.js { if params[:format] == "raw" render :text => @annotation.body.to_s else render :text => @annotation.body.to_html end } end end This is from jQuery, but I'm doing the right beforeSend stuff: $.ajaxSetup({ beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "text/javascript"); }, cache: false }); Here are my request headers: Host localhost:3000 User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 Accept text/javascript Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive X-Requested-With XMLHttpRequest Content-Type application/x-www-form-urlencoded

    Read the article

  • jquery json null when using localhost

    - by Eeyore
    I am trying to load json generated by my django app. It works when I save the json output and load it from a static file. However, when I make a call to a server it returns null. JSON {"users": [ { "id": 1, "name": "arnold" }, { "id": 2, "name": "frankie" } ]} Ajax call $.ajax({ url: "http://localhost:8000/json", //vs. json.js dataType: 'json', type: 'get', timeout: 20000, error: function() { alert("error"); }, beforeSend: function() { alert("beforeSend"); }, complete: function() { alert("complete"); }, success: function(data) { alert(data.users[0].name); } }); view.py return HttpResponse(simplejson.dumps(data), content_type = 'application/json; charset=utf8')

    Read the article

  • jquery addresses and live method

    - by Jay
    //deep linking $.fn.ajaxAnim = function() { $(this).animW(); $(this).html('<div class="load-prog">loading...</div>'); } $("document").ready(function(){ contM = $('#main-content'); contS = $('#second-content'); $(contM).hide(); $(contM).addClass('hidden'); $(contS).hide(); $(contS).addClass('hidden'); function loadURL(URL) { //console.log("loadURL: " + URL); $.ajax({ url: URL, beforeSend: function(){$(contM).ajaxAnim();}, type: "POST", dataType: 'html', data: {post_loader: 1}, success: function(data){ $(contM).html(data); $('.post-content').initializeScroll(); } }); } // Event handlers $.address.init(function(event) { //console.log("init: " + $('[rel=address:' + event.value + ']').attr('href')); }).change(function(event) { evVal = event.value; if(evVal == '/'){return false;} else{ $.ajax({ url: $('[rel=address:' + evVal + ']').attr('href'), beforeSend: function(){$(contM).ajaxAnim();}, type: "POST", dataType: 'html', data: {post_loader: 1}, success: function(data){ $(contM).html(data); $('.post-content').initializeScroll(); }}); } //console.log("change"); }) $('.update-main a, a.update-main').live('click', function(){ loadURL($(this).attr('href')); return false; }); $(".update-second a, a.update-second").live('click', function() { var link = $(this); $.ajax({ url: link.attr("href"), beforeSend: function(){$(contS).ajaxAnim();}, type: "POST", dataType: 'html', data: {post_loader: 1}, success: function(data){ $(contS).html(data); $('.post-content').initializeScroll(); }}); return false; }); }); I'm using jquery addresses to update content while maintaining a useful url. When clicking on links in a main nav, the url is updated properly, but when links are loaded dynamically with ajax, the url address function breaks. I have made 'click' events live, allowing for content to be loaded via dynamically loaded links, but I can't seem to make the address event listener live, but this seems to be the only way to make this work. Is my syntax wrong if I change this : $.address.change(function(event) { to this: $.address.live('change', function(event) { or does the live method not work with this plugin?

    Read the article

  • Not Seeing Ajax Requests In Firebug If Header Has Been Modified

    - by FluidFoundation
    Hey braintrust, I'm making an ajax call using jQuery's library to an api, which requires a username and password encoded to base64 be added to the header. here's a basic example: $.ajax({ type: "GET", contentType: 'application/json', beforeSend:function(xhr){ xhr.setRequestHeader("Authentication", "Basic " + base64EncodedValue); } url: 'https://api.company.com/uri/', complete: function(result) { alert(result); } }); But when this fires off, I get a black alert box, so it doesn't appear as if something is coming back. There is no log in the Firebug console that a get ajax request was done. However, if I remove the beforeSend option, I do see the ajax request get logged, but the request gets back a 'not authorized', so it definitely hit the right place. Any ideas on why it's not showing up in Firebug so I can verify the headers are being sent out correctly?

    Read the article

  • Showing a loading spinner only if the data has not been cached.

    - by Aaron Mc Adam
    Hi guys, Currently, my code shows a loading spinner gif, returns the data and caches it. However, once the data has been cached, there is a flicker of the loading gif for a split second before the data gets loaded in. It's distracting and I'd like to get rid of it. I think I'm using the wrong method in the beforeSend function here: $.ajax({ type : "GET", cache : false, url : "book_data.php", data : { keywords : keywords, page : page }, beforeSend : function() { $('.jPag-pages li:not(.cached)').each(function (i) { $('#searchResults').html('<p id="loader">Loading...<img src="../assets/images/ajax-loader.gif" alt="Loading..." /></p>'); }); }, success : function(data) { $('.jPag-current').parent().addClass('cached'); $('#searchResults').replaceWith($(data).find('#searchResults')).find('table.sortable tbody tr:odd').addClass('odd'); detailPage(); selectForm(); } });

    Read the article

  • I can't change HTTP request header Content-Type value using jQuery

    - by Matt
    Hi I tried to override HTTP request header content by using jQuery's AJAX function. It looks like this $.ajax({ type : "POST", url : url, data : data, contentType: "application/x-www-form-urlencoded;charset=big5", beforeSend: function(xhr) { xhr.setRequestHeader("Accept-Charset","big5"); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=big5"); }, success: function(rs) { target.html(rs); } }); Content-Type header is default to "application/x-www-form-urlencoded; charset=UTF-8", but it obviously I can't override its value no matter I use 'contentType' or 'beforeSend' approaches. Could anyone adivse me a hint that how do I or can I change the HTTP request's content-type value? thanks a lot. btw, is there any good documentation that I can study JavaScript's XMLHttpRequest's encoding handling?

    Read the article

  • How can I get jQuery validation plugin Ketchup to stop an Ajax form submission when validation fails?

    - by Marshall Sontag
    I'm using Ruby on Rails, Formtastic gem, jQuery and ketchup to validate my form. I'm submitting the form created by Formtastic inside a modal box using ajax: <% semantic_form_remote_for @contact_form, :url => '/request/contact' do |f| %> I have a validation plugin verifying the fields on the form: $(document).ready(function() { $("#new_contact_form").ketchup(); }); The problem is that semantic_form_remote_for generates an onSubmit ajax request that the jQuery validation plugins won't prevent, since it's not a normal form submission. One question on stackoverflow suggests using :condition on the remote form declaration to fire a javascript function, but I can't do that since I'm not using a function, but rather relying on a jQuery handler. I also tried putting ketchup within a submit event handler: $(document).ready(function() { $("#new_contact_form").submit(function() { $('#new_contact_form').ketchup(); }); }); No luck. Form still submits. I also tried using the beforeSend option of jQuery.ajax: $(document).ready(function() { jQuery.ajax( { beforeSend: function(){ $('#new_contact_form').ketchup(); } }); }); Validation fires off, but form is still submitted. I switched to jQuery Validation plugin just to see if it was due to some limitation in Ketchup. It turns out that Validation has a submitHandler option: $(document).ready(function() { $('#new_contact_form').validate({ submitHandler: function(form) { jQuery.ajax({ data:jQuery.param(jQuery('#new_contact_form').serializeArray()), dataType:'script', type:'post', url:'/request/contact' }); return false; } }); }); This works when I use a regular semantic_form_for instead of semantic_form_remote_for, but alas, I would rather use Ketchup. Is Ketchup just woefully lacking? Am I forced to use jQuery Validation?

    Read the article

  • jQuery addClass() not running before jQuery.ajax()

    - by Josh
    I'm trying to have a button that onclick will apply a class loading (sets cursor to "wait") to the body, before making a series of ajax requests. Code is: $('#addSelected').click(function(){ $('body').addClass('loading'); var products = $(':checkbox[id^=add_]:checked'); products.each(function(){ var prodID = $(this).attr('id').replace('add_', ''); var qty = $('#qty_' + prodID).val(); if($('#prep_' + prodID).val()) { prodID += ':' + $('#prep_' + prodID).val(); } // Have to use .ajax rather than .get so we can use async:false, otherwise // product adds happen in parallel, causing data to be lost. $.ajax({ url: '<?=base_url()?>basket/update/' + prodID + '/' + qty, async: false, beforeSend: function(){ $('body').addClass('loading'); } }); }); }); I've tried doing $('body').addClass('loading'); both before the requests, and as a beforeSend callback, but there is no difference. In firebug I can see that body doesn't get the loading class until after the requests are complete. Any ideas?

    Read the article

  • Django url rewrites and passing a parameter from Javascript

    - by William T Wild
    As a bit of a followup question to my previous , I need to pass a parameter to a view. This parameter is not known until the JS executes. In my URLConf: url(r'^person/device/program/oneday/(?P<meter_id>\d+)/(?P<day_of_the_week>\w+)/$', therm_control.Get_One_Day_Of_Current_Thermostat_Schedule.as_view(), name="one-day-url"), I can pass it this URL and it works great! ( thanks to you guys). http://127.0.0.1:8000/personview/person/device/program/oneday/149778/Monday/ In My template I have this: var one_day_url = "{% url personview:one-day-url meter_id=meter_id day_of_the_week='Monday' %}"; In my javascript: $.ajax({ type: 'GET', url: one_day_url , dataType: "json", timeout: 30000, beforeSend: beforeSendCallback, success: successCallback, error: errorCallback, complete: completeCallback }); When this triggers it works fine except I dont necessarily want Monday all the time. If I change the javascript to this: var one_day_url = "{% url personview:one-day-url meter_id=meter_id %}"; and then $.ajax({ type: 'GET', url: one_day_url + '/Monday/', dataType: "json", timeout: 30000, beforeSend: beforeSendCallback, success: successCallback, error: errorCallback, complete: completeCallback }); I get the Caught NoReverseMatch while rendering error. I assume because the URLconf still wants to rewrite to include the ?P\w+) . I seems like if I change the URL conf that breaks the abailty to find the view , and if I do what I do above it gives me the NoREverseMatch error. Any guidance would be appreciated.

    Read the article

  • Modifying jQuery ajax request Connectino header

    - by Pat
    I'm trying to modify the Connection header with the following code with no success jQuery.ajax ( { url: URL, async: boolVariable, beforeSend: function(xhr) { xhr.setRequestHeader("Connection", "close"); } } ) The request headers via Firebug show: Connection keep-alive X-Requested-With XMLHttpRequest Any odd bugs/problems with setting this particular header known? Or is there something I'm doing wrong?

    Read the article

  • Modifying jQuery ajax request Connection header

    - by Pat
    I'm trying to modify the Connection header with the following code with no success jQuery.ajax({ url: URL, async: boolVariable, beforeSend: function(xhr) { xhr.setRequestHeader("Connection", "close"); } }) The request headers via Firebug show: Connection keep-alive X-Requested-With XMLHttpRequest Any odd bugs/problems with setting this particular header known? Or is there something I'm doing wrong?

    Read the article

  • Why doesn't my javascript work after AJAX filling the HTML?

    - by alex
    $.ajax({ method:"get", url:"/details/", data:"id="+id, beforeSend:function(){ }, success:function(html){ $("#holder").html(html); } }); After I fill a div with a HTML from an AJAX call, this is my javascript at the top of /details/ <script type="text/javascript"> alert('hi'); </script> MY DETAILS HTML CONTENT GOES HERE But it's not working

    Read the article

  • How do I return something in JQuery?

    - by TIMEX
    function vote_helper(content_id, thevote){ var result = ""; $.ajax({ type:"POST", url:"/vote", data:{'thevote':thevote, 'content_id':content_id}, beforeSend:function() { }, success:function(html){ result = html; } }); return result; }; I want to return the result. But it's returning blank string.

    Read the article

  • Javascript jQuery ajax submit default data

    - by onlineracoon
    How to submit default data when using $.ajax? I have tried: $.ajaxPrefilter(function(options, originalOptions, jqXHR) { // can't access anything here... (tried jqXHR.data but undefined) }); $.ajaxSetup({ beforeSend: function(jqXHR, settings) { // can't access anything here... (tried jqXHR.data but undefined) } }); I need this so I can send my CSRF token, each time and when logged in submit the user ID each time. I prefer not to submit a token in headers. Thanks

    Read the article

  • Passing Custom Headers to Ajax request on Select2

    - by Sutikshan Dubey
    We are trying to implement Ajax Remote data loading in Select2:- $scope.configPartSelect2 = { minimumInputLength: 3, ajax: { url: "/api/Part", // beforeSend: function (xhr) { xhr.setRequestHeader('Authorization-Token', http.defaults.headers.common['Authorization-Token']); }, // headers: {'Authorization-Token': http.defaults.headers.common['Authorization-Token']}, data: function (term, page) { return {isStockable: true}; }, results: function (data, page) { // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to alter remote JSON data return { results: data }; } } }; We are using AngularJS. With each Http request we have set it's default to have our Authtoken as header. But somehow it is not working in conjunction with Select2 Ajax request. In above code, commented code are my failed attempts.

    Read the article

  • IE8 + Jquery ajax call giving parsererror : for json data which seems valid in Firefox

    - by PlanetUnknown
    The ajax call works fine in FF. the data returned is in JSON here is an example from FF firebug - {"noProfiles": "No profiles have been created, lets start now !"} When I try to print the error in IE8 (& in compatibility modes as well), it says "parsererror". But the output seems to be valid JSON. Here is the ajax function call I'm making. Any pointers would be great ! $.ajax({ type: "GET", url: "/get_all_profile_details/", data: "", dataType: "json", beforeSend: function() {alert("before send called");}, success: function(jsonData) { alert("data received"); }, error: function(xhr, txt, err){ alert("xhr: " + xhr + "\n textStatus: " + txt + "\n errorThrown: " + err); } }); The alerts in the error function above give - xhr:<blank> textstatus:parsererror errorThrown: undefined Any pointers would be great ! Note : jquery : 1.3.2

    Read the article

  • echoing javascript when an ajax funtion is called

    - by Roland
    I'm doing a ajax call via the normal jquery ajax funtion My ajax looks as follows jQuery('#yt10').live('click',function(){jQuery.ajax({'data':{'set':$("#booking_set_id1").val(),'setStat':$("#booking_stockStatus").val(),'setNum':$("#booking_setNum").val()},'beforeSend':function(){ if($("#booking_set_id1").val() == "" || $("#booking_stockStatus").val() == "" || $("#booking_setNum").val() == ""){ $("#error").addClass("flash-error"); $("#error").html("Please fill in all relevant set details before adding a set"); return false; } },'dataType':'html','success':function(data,status){ $("#mainrow").show(); $("#error").removeClass("flash-error"); $("#error").html(""); $("#setTable tr:last").after(data); $("#booking_set_id1").val(""); $("#booking_stockStatus").val(""); $("#booking_setNum").val(""); },'url':'/booking/newSet','cache':false});return false;}); Now the function newSet needs to echo javascript to the bowser but somehow jquery filters the javscript out. Is it possible to echo javascript via ajax

    Read the article

  • jQuery UI dialog + Ajax fails with IE 6-7-8

    - by user252849
    hey i have problem with jQuery-ui Dialog when using ajax $.ajax({ url: "folders.php", cache: false, data: { 'do' : 'Ajax' ,'_a' : 'ChangeMoviesFolder' ,'MovieIDS' : MovieIDS ,'toFolderID' : toFolderID ,'fromFolderID' : fromFolderID }, context: document.body, open: function(event, ui) { alert('open'); }, error : function(XMLHttpRequest, textStatus, errorThrown){ // Handle the beforeSend event // alert("responseText: "+errorThrown.message); }, success: function(data){ $('input.checkMovie').attr('checked',0); $("#resultsTable").find('tr.selectable-row').removeClass('active'); if (data == '1') { window.location = WWW_ROOT+'movies.php?do=List&FolderID='+toFolderID; } $dialog.dialog("close"); }}); when using IE ajax never get to success option in error i got "This method cannot be called until the open method has been called" Its happen only in IE. Does any one may know what the problem might be ? (all vars are ok and works perfectly in FF & chrome) thanks.

    Read the article

  • How to use the context variable in ajaxSetup with jquery

    - by user1730491
    I have multiple forms on one page and i am submitting them via Ajaxform plugin like this <td> <form> form1 </form> </td> <td> <form> form2 </form> </td> var options = { target: '.ajaxMessage', dataType: 'json', // pre-submit callback success: function(data, statusText, xhr, form){ myResponse(data,form)}, context: { element: this}, cache: false, delegation: true, type: 'POST' }; $(".rform").ajaxForm(options); In mY AjaxSetup , i have this beforeSend:function(xhr, settings){ $this = settings.context.element; alert($this); But its not working , alert says window object

    Read the article

  • JQuery response is null but actual response is not

    - by Paul Petrick
    I'm using JQuery to make an Ajax call. I used a sniffer to catch the response text: {"error_code":0,"message":"SUCCESS","data":{"session_token":"3efd9dde-a839-4e91-9415-4c2f6cba5b7b"}} But the response returned on the success callback is null. Anyone got any ideas? (see jquery code below. Jquery code: $.ajax({ type: "GET", url: "http://184.72.58.99/matchaapi/API/User/Login", data: { email: emailval, password: pwordval, developer_key: devkey }, dataType: "json", cache: false, beforeSend: function(xhr) { xhr.setRequestHeader( "Content-Type", "application/json; charset=utf-8" ); }, success: function(resp) { alert(resp); $("#status p").html(resp.message); }});

    Read the article

  • JQuery,ajax problem?

    - by user303832
    Hello,I have one table,and when I click on row,it load some content in another table,problem is,when I first time click on row it loads just one time(message 'Some msg' and message 'Some other msg' is showen one time),when I click on other row,it loads twice(messages is shown twice),third time when I click on row it loads three times,ets.Here is my code. $.ajax({ url:'<?php echo $full_path_ajax_php; ?>', data:{'what':'2','mypath':'12345678'}, dataType:'json', type: 'GET', beforeSend:function(){alert('Some msg')}, success: function(){alert('Some other msg')} }); return false; Can someone help me please to understand this.Tnx in advance.

    Read the article

1 2 3  | Next Page >