Category Archives: Ajax

Loading a page via Ajax into Div Best Practice?

Questions: I’m using the method below to load a remote page into a div I have on the page. $(‘#result’).load(‘’); I’m curious, is it a bad practice to load an entirely formatted HTML page within another page? My concern is more towards loading css or additional javascript includes that might overwrite other elements on the… Read More »

Chained jQuery promises with abort

Questions: I’m currently writing API code which, several layers deep, wraps $.ajax() calls. One requirement is that the user must be able to cancel any request (if it’s taking too long, for example). Normally this is accomplished via something simple, like: var jqXHR = $.ajax(..); $(mycancelitem).click(function () { jqXHR.abort(); }); However my code looks more… Read More »

node.js equivalent of a standard PHP ajax saving scheme

Questions: In a JavaScript (client) + PHP (server) website, I have this scheme for saving an “online notepad” (in a #textbox textarea) to server: // client-side $(“#save-button”).on(‘click’, save); function save(e) { $.ajax({ type: “POST”, url: “/php/save.php”, data: { projectname: $(‘#projectname’).text(), data: $(‘#textbox’).text() }, success: function(data) { alert(‘Data saved’); }, error: function(data) { console.log(data); } });… Read More »

dataType vs accepts – Ajax Request

Questions: I am trying to understand the difference between accepts and dataType in a Ajax Request. Documentation states: Documentation accepts (default: depends on DataType) Type: PlainObject The content type sent in the request header that tells the server what kind of response it will accept in return. dataType (default: Intelligent Guess (xml, json, script, or… Read More »

Loading more eloquent hasMany relation queries through ajax in Laravel?

Questions: On my site, users can post “statuses”, and other users can reply/comment on those statuses. On the front page of my site, for example, I have the most liked statuses of the past 3 days displayed. In my HomeController.php: $statuses = Status::where(‘is_image’, 1) ->where(‘is_mature’, 0) ->where(‘created_at’, ‘>=’, Carbon::now()->subHours(168)) ->orderBy(‘like_count’, ‘desc’) ->take(6) ->get(); Statuses can… Read More »

Stop Master page refreshing while navigating between pages?

Questions: I’m using Master Page in my application, in the master page I put a ContentPlaceHolder in Update Panel to support AJAX in child pages, the question is how to stop Refreshing “master page controls” while navigating between pages? For navigation between pages I tried to use Response.Redirect, windows.location java script with no success,… Read More »

Parsing XML namespaces?

Questions: Using JavaScript/Ajax? I’m trying to extract values from: <yweather:astronomy sunrise=”6:34 am” sunset=”8:38 pm”/> Looking for something like: var response = transport.responseXML.getElementsByTagName(“channel”); sunrise = response[0].getElementsByTagName(“yweather:astronomy”).item(0).Attributes[“sunrise”].Value; But nothing works so far. :'( Thanks. Answers: There is a special version of getElementsByTagName for namespaces: getElementsByTagNameNS. For example: var response = transport.responseXML.getElementsByTagName(“channel”); var sunrise = response[0].getElementsByTagNameNS(“[Namespace URI]”, “astronomy”)[0].getAttribute(“sunrise”);… Read More »

jQuery AJAX timeout undefined

Questions: I was trying out example jQuery examples and to my surprise, I got an error state for an AJAX call mentioning that timeout isn’t defined. When I removed timeout attribute, it worked fine. I downloaded jQuery few days back, so I am pretty sure it’s not a version problem. I was trying with Firefox(3.6.8)… Read More »

What do you use for client to server communication with GWT?

Questions: GWT RPC is proprietary but looks solid, supported with patterns by Google, and is mentioned by every book and tutorial I’ve seen. Is it really the choice for GWT client/server communcation? Do you use it and if not why and what you chose? I assume that I have generic server application code that can… Read More »