I have Content Panel in which I add an image object without assigning an URL. Then I do a request to the server to return the URL of an image in the onSuccess method, but the image is not shown.
If I set the URL without calling server-side code it works, but when I use image.setUrl in the onSuccess method it doesn't work.
Do you know how to paint an image asynchronously?
Thanks in advance!
Make server call before rendering screen. After you receive response from server in success method make rendering of screen.
Related
I'm uploading an image to my server by URL. The URL is sent by Ajax Call, PHP handles the upload and send back the image ID to ajax call. After that I need to set the image as featured image but I can't get it working.
I've already confirmed that data sent back to ajax call is the correct image ID, but when using the following code, nothing happens:
wp.media.featuredImage.set( data ); //data is the ID of the image sent by PHP
I guess I'm missing something but can't figure out what.
I display information, gather some user's input, and call a controller method using ajax/java script call from the view. However, instead of displaying a new/different html page, the controller method returns back to the original html page that I called jscript from.
Is this because of ajax call? How do I make sure that controller method would display the html file it's supposed to, instead of staying on old html page?
It sounds to me like what you want to do is to open a different url than the one you are on. To do that you do not use ajax. Instead try using javascript to change window.location to tell the browser to go to the url (or 'call your controller'). It looks like this:
window.location.assign("/your/controller/url"); // or
window.location = "/your/controller/url";
There is more to read about it here: https://developer.mozilla.org/en-US/docs/Web/API/Window.location
You can think of ajax as a separate little browser that lets you call the web server but letting you handle what comes back with javascript rather than always showing it to the user. So if you want to do the call with ajax but get the response HTML into your page, you are responsible for taking that response and inserting it into the DOM.
As we know, GET method sends data via URL. We can use both GET and POST method in ajax. My question is, why can't we see the data in URL when we use ajax with a GET method?
AJAX call is not visible through url.
Try to use firebug extension of firefox.
In firebug, you will find all request in console.
When you fire off your ajax request like this:
The Chrome network tab will show new line for this transaction:
If you click on it, it will show you all the details:
If you'd like more information on constructing your own querystrings, look at this other question: How to build query string with Javascript
I have the following problem with my application (jQuery-mobile with Phonegap)
I need to call a function with a ajax call, that returns a URL of a image, after load the json response take the URL and load an image on top of the main screen.
My problem is, because the screen is the first screen after application loaded, the user see and wait in the splash screen and after, the application show the page full rendered instantally.
My application on Blackberry devices delay more that 10s on the splash screen, but, I comment the ajax code, the app loads in 4s.
I tried to put the function in:
..live("pageaftershow", function().. with same result, always call the function, parse json and load image BEFORE the user see the screen.
How can I make sure that this function call effectively after the user see the screen?
Thanks!
try doing the ajax call on deviceready
document.addEventListener("deviceready",function(){
// do stuff
},false);
Goal:
I want to let my users download a file on my webpage. I want a new window to open and the file to be either displayed or downloaded there.
My implementation:
This file however, first has to be generated on the server-side, which might take a while. When the user clicks the button to download the file, I do an ajax call and show a waiting animation until I get a response. The controller action that handles the call will generate the file (PDF) and return a FileResult. Now in the succes function of my ajax call back in javascript, I get the file data.
Problem: I have no Idea what I'm supposed to do with this data to get it to the user.
Workaround:
Right now I use a workaround where I do not return the file in the ajax call, but store it in session. In the succes function I do window.open("/controller/getPDFFromSession") which will download the file. However, I prefer not to use the session for these kind of things.
Thanks in advance.
Problem: I have no Idea what I'm supposed to do with this data to get it to the user.
You shouldn't use AJAX for downloading files for this reason. You could do the following:
The user clicks on the download button
Using javascript you show some progress image informing him that he will have to wait
Using javascript you generate and inject a hidden iframe into the DOM having its src property pointing to the controller action supposed to generate the file
Once the iframe is loaded you could hide the progress image