Meteor HTTP.call and jquery ajax - ajax

I would like to use Meteor.call('GET') instead of $.ajax(). I have an ajax call as the following:
$.ajax({
url: url,
crossDomain:true,
type: method,
data: query,
dataType: 'json'
}).done(function(data) {
_tokens.request = {
token: data.oauth_token,
secret: data.oauth_token_secret.split('')
};
});
Have some options but I don't know how to pass to Meteor.call(). Please help!
Thank you so much

You probably mean HTTP.call or HTTP.get. Meteor.call is related to another concept.
http://docs.meteor.com/#/full/http_get

Related

Ajax serialise - issue with data format

I have several inputs formatted with this jquery plugin here.
I use $.ajax to do my mysql insert:
$.ajax({
type: 'GET',
url: 'xxxx.php',
data: $('#new_form').serialize(),
}),
I face an issue as my input values are formatted with the plugins and can't get into mysql db.
As an example:
Input value: $450,000.00 is not accepted.
Is there a way to unformat within the serialise function values that have a specific classes (like class="money")?
Thanks for your help!
I have tried the below code:
$.ajax({
type: 'GET',
url: 'xxx.php',
data: $('#new_form').serialize(),
dataType:"json",
beforeSend: function(){
$(".money").cleanVal();
},
<script>
function cleanVal(v) {
return v.replace(/^\,/,'');
};
</script>
the result of the insert in mysql is still 450 for 450,000.
Do you have an idea?
thanks
You can try using the plugin $.cleanVal() method to retrieve the unmasked type value of the corresponding HTML element, prior to your AJAX form submission. So something like this:
$.ajax({
type: 'GET',
url: 'xxxx.php',
data: $('#new_form').serialize(),
beforeSend: function(){
$(".money").cleanVal();
}
}),
I couldn't make it work with beforehand. I found a solution which is to unmask values before calling ajax.
If anyone knows why it does not work with beforesend, thanks for letting me know.
cheers

Alternative method to ajax json

I develop a web solution for a company and I want to get php variables to my pages using ajax. The problem is that the server of that company is somewhat old and I cannot use json using jason_encode for that. Is there any alternative method to do that without using json? Help would be really appreciated.
formData = {
// all your parameters here
param1: param1,
param2: param2
}
$.ajax({
type: 'POST',
contentType: 'application/json',
url: "https://www.example.com/test",
dataType: "json",
data: formData,
success: function(data) {
//success handling
},
error: function(data) {
//error handling
}
});

Ajax data collect in code lines

I did some admin panel in wordpress sheet but i'm adding options and have everything in one line in the data, it's pain if I keep adding options, works that way but it looks messy.
example
$.ajax({
type: 'POST',
url: ajaxurl,
data: 'action=general_settings_action&zkr_logo='+zkrlogo+'&zkr_favicon='+zkrfavicon+'&zkr_background='+zkrbackground+'&zkr_linkcolor='+zkrlinkcolor+'&zkr_linkhover='+zkrlinkhover+'&zkr_colorbackground='+zkrcolorbackground,
success: function(data){
alert(data);
}});
I would like to make some lines to that data field like for example
$.ajax({
type: 'POST',
url: ajaxurl,
data:
'action=general_settings_action&
zkr_logo='+zkrlogo+'&
zkr_favicon='+zkrfavicon+'&
zkr_background='+zkrbackground+'&
zkr_linkcolor='+zkrlinkcolor+'&
zkr_linkhover='+zkrlinkhover+'&
zkr_colorbackground='+zkrcolorbackground,
success: function(data){
alert(data);
}});
But putting the code like that doesn't work I have tried with \n and some other stuff but still wont do the work.
I apreciate the help... Thanks
Try doing this:
Make a JSON data object that contains the parameters you want to send
var DATA = {
action:'general_settings_action',
zkr_logo:zkrlogo,
zkr_favicon:zkrfavicon,
zkr_background:zkrbackground,
zkr_linkcolor:zkrlinkcolor,
zkr_linkhover:zkrlinkhover,
zkr_colorbackground:zkrcolorbackground
}
The send the data in your AJAX request using the data field
$.ajax({
type: 'POST',
url: ajaxurl,
data: DATA,
success: function(data){
alert(data);
}});
I checked this out at: David Walsh's guide
You need to add
'zkr_logo=' + zkrlogo + '' +
instead of
zkr_logo='+zkrlogo+'&
then it will form one String

How to send json in post body with jQuery mobile

Please help me, what is wrong in this code?
$.ajax({
type: 'POST',
url: baseUrl+url,
data: {language: 'it'},
xhrFields: {
withCredentials : true
}
})
why server receives:
'language=it_IT'
Try to specify your dataType and use JSON.stringify():
$.ajax({
type: 'POST',
url: baseUrl+url,
data: JSON.stringify ({language: 'it'}),
xhrFields: {
withCredentials : true
},
contentType: "application/json",
dataType: 'json'
})
I just run through the same issue: for some reason, whenever you send language parameter using ajax it somehow automatically changes to get and all post parameters get lost. Solution: avoid using language parameter at all (or stringify yout data as #Agash Thamo suggested. That is strange for me and I would really like if somoeno could explain that a little bit better.

working XML feed , blogger is an exception?

This is a working fiddle. http://jsfiddle.net/bpBtC/1/
But this http://jsfiddle.net/bpBtC/131/ doesn't work with the same method?
(All the other websites with XML feeds also fail using the same method, why?)
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://www.blogger.com/feeds/2399953/posts/default",
dataType: "xml",
success: xmlParser,
dataType: 'jsonp'
});
});
function xmlParser(xml) {
$(xml).find("entry").each(function () {
$(".entirecont").append($(this).find('title').text());
});
}
You are setting dataType twice.
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://www.blogger.com/feeds/2399953/posts/default",
dataType: "xml",
success: xmlParser,
dataType: 'jsonp' //<-- this is what actually used.
});
Remove the second dataType and your code will fail.http://jsfiddle.net/bpBtC/130/
The first fiddle works because it is using JSONP (not XML) as the return data type and a method of circumventing the cross-site scripting restrictions. Familiarize yourself with JSONP and how it works.
The second feed does NOT return JSONP, it returns XML and so it can't work. Also you can't have two datatype-parameters on same ajax-call.

Resources