AJAX Not returning - ajax

alert("orger");
$.ajax({
type: "GET",
url: "localhost:8080/greeting",
success: function(data) {
alert("hello");
}
});
The browser outputs "orger", but not "hello". What is the issue? When I invoke the url in the browser, the page renders successfully.

The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. , use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

too many possibilities for Ajax not returning.
- It might be jQuery not plugged
- url not found.
- HttpService got error, so it goes in error part.
- etc.
so look at the below link, i will help you.
enter link description here

Related

Framework7 on ajax success navigating to another page is not working

So i'm using phonegap/framework7 for an app i'm working on
i have the following ajax call which works just fine..
$.ajax({
method: "POST",
url: myApi+ "ratings",
data: ratingForm,
success: function() {
//works fine
alert("test success");
//this part doesn't work!
app.router.navigate("/success/");
},
error: function () {
app.dialog.alert('We apologize, an error
occurred while trying to saving your rating. Please try
again.');
}
});
The part not working is the app.router.navigate("/success/"); part. I have no errors in the console. This function DOES work if called from anywhere else in the program, so i'm not sure how to handle redirecting after an ajax success, any help would be much appreciated.
i think you were supposed to use:
app.mainView.router.navigate('/success');
The missing part is the mainView
after lots of playing eventually, I got it working...
I'm using a tabbed layout, I have the following in app.js
var composeView = app.views.create('#view-compose', {
url: '/compose/'
});
and on my ajax success i'm now doing...
composeView.router.navigate("/success/");
and it's routing properly, thank you to everyone who helped!

issue with Ajax dispatcher in typo3

I'm trying to grab some data from the database on a page in typo3 using Ajax . So after a long time looking for the appropriate way to do it , I got convinced that The Ajax Dispatcher is the best tool to do the job . So I created the file following the instructions to be found here.
Now when I make an Ajax call on my page , the console displays a 500 (Internal Server Error).
joined is a snapshot of my console tab.
and this is the jquery function that gets run on an onchange event .
function getContent(id)
{
console.log("Start process ...");
$.ajax({
async: 'true',
url: 'index.php',
type: 'POST',
data: {
eID: "ajaxDispatcher",
request: {
pluginName: 'listapp',
controller: 'Pays',
action: 'getMyCos',
arguments: {
'id': id,
}
}
},
dataType: "json",
success: function(result) {
console.log(result);
},
error: function(error) {
console.log(error);
}
});
}
Could someone please help me , I just started developing with this CMS of shit :p
If you indeed followed the tutorial step by step, and you use TYPO3 V6.2, you would get errors cause of depricated function calls to t3lib_div (as the title of the blog item says, it is for version 4.x)
Always keep your error.log open, it's your best friend in times of coding stress
You can also use typenum for ajax calls
http://lbrmedia.net/codebase/Eintrag/extbase-60-ajax-bootstrap/
I can imagine that starting with TYPO3 can be frustrating, but calling it a 'CMS of shit' does not seems to be a smart strategic move if you need help from people who think differently about it.

error in jsonp call ONLY FROM firefox-extension

what's weird about my error is that it ONLY occurs in the firefox extension I have linked to at the bottom of this post. I cannot reproduce this error in any other setting.
I have this ajax request
$.ajax({
type: "GET",
dataType: "jsonp",
url: url,
jsonpCallback: "JSONCallback",
data: {title:$("#txtTitle").val(), url:taburl},
success: function(data, textStatus) {
if(data.code > 0)
{
$("#icon").removeClass().addClass('accept');
}
else
{
$("#icon").removeClass().addClass('error');
if(data.code == '-1')
alert('kunne ikke finde din ønskeseddel på e-ønsker.dk - besøg e-ønsker.dk, og prøv derefter igen');
}
},
error: function(xhr, textStatus, errorThrown) {
alert("XMLHttpRequest="+xhr.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
$("#icon").removeClass().addClass('error');
}
});
server returns
JSONCallback({"code":405});
headers are application/json
so why am I getting a parseError saying JSONCallback was not called? I thought jQuery was supposed to handle that for me?
the code is from http://builder.addons.mozilla.org/addon/1022928/latest and the file in question is data/panel.js
The problem is with window. The easiest way to fix this will be to edit the jQuery code (I know, I hate doing this too) to use unsafeWindow rather than window.
have you tried to enable the"Cross-Origin Resource Sharing"
using :
jQuery.support.cors = true;
i had the same issue with firefox a while ago and using that line before making my ajax call fixed it for me.
i coulnd get your fizzle to work for some reason :) good luck
This isn't really an answer, but why are you using jsonp? Code running in the context of a Firefox extension isn't subject to the cross origin restriction.
My understanding of jsonp is that a script tag is added to the document using the server's response so that your callback is executed. In a Firefox extension "document" is the XUL UI not the regular page's document. I'm not sure that adding a script element to XUL will cause the browser to execute that script.
Hope this helps!

WORDPRESS : Ajax and template

I have a question.
How can I use Ajax on my templates...
in single.php I have :
$.ajax({
type: "POST",
url: "http://www._____wp-content/themes/MS-MangoBerry___/myajax.php",
data: "yo",
cache: false,
success: function(data)
{
alert("yes");
}
});
And in myajax.php, I have
$(document).ready(function() {
alert("ok"); });
Then I have an error : Fatal error: Call to undefined function get_header() in myajax.php
Why ?
Thanks in advance.
Please also have a look at this article http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/#js-global
It suggests that all AJAX requests should be submitted to /wp-admin/admin-ajax.php
And the you could hook the request by using this code in functions.php
add_action('wp_ajax_your_ajax_action_name', 'method_name');
add_action('wp_ajax_nopriv_your_ajax_action_name', 'method_name');
Then you could implement a method in functions.php
function method_name()
{
// do something or echo XML to return stuff
}
On the request you also need to send a parameter name 'action' with value of the action name.
in this case it would be action=your_ajax_action_name.
Hope this help :)
wordpress has a built ajax url that you need to use. this post will help you out.
http://geekpreneur.blogspot.com/2009/06/how-to-use-wpajax-in-wordpress.html
the tricky thing is how wordpress knows which function will accept your call back. it happens by adding an action. the hook of the action is your ajax action prepended with wp_ajax_

jQuery: How to enable `beforeSend` for `$.ajax({dataType:'jsonp'...`? Is there any solution?

jQuery: How to enable beforeSend for $.ajax({dataType:'jsonp'...? Is there any solution?
http://jsfiddle.net/laukstein/2wcpU/
<div id="content"></div>
<script>
$.ajax({
type:"GET",
url:'http://lab.laukstein.com/ajax-seo/.json',
dataType:'jsonp',
async:false,
beforeSend:function(data){ // Are not working with dataType:'jsonp'
$('#content').html('Loading...');
},
success:function(data){
$('#content').html(data.content);
}
});
</script>
This is just the nature of how JSONP works, creating a <script> tag, not actually using a XMLHttpRequest to get data.
For what you're doing, you can just run the code before, like this:
$('#content').html('Loading...');
$.ajax({
type:"GET",
url:'http://lab.laukstein.com/ajax-seo/.json',
dataType:'jsonp',
async:false,
success:function(data){
$('#content').html(data.content);
}
});
As per jQuery documentation
When data is retrieved from remote
servers (which is only possible using
the script or jsonp data types), the
operation is performed using a
tag rather than an
XMLHttpRequest object. In this case,
no XMLHttpRequest object is returned
from $.ajax(), and the XMLHttpRequest
object and the textStatus arguments
passed to the handler functions such
as beforeSend will be undefined. The
error callback will never be fired for
JSONP requests.
The same question is asked at the jQuery forums ajax:beforeSend for jsonp requests don't fire
The question's status is Status : Working on it. So it might be there at a future release.
And as Mike Alsups noted
I would name than function something
other than 'beforeSend' since the
semantics are not the same.
Also related : jsonp is not firing beforeSend?
Cannot use beforeSend with jsonp. Period.
you can use this code:
befor $.ajax put it, and you should have an image(or div,span ,...) loading with "div_loading" id.
$("#div_loading").ajaxStart(function(){$(this).show();});
$("#div_loading").ajaxStop(function(){$(this).hide();});

Resources