Framework7 (Dom7): JSONP - jsonp

I am using Fremework7 v1.4.0 and there is no jsonpCallback or jsonp and other related JSONP parameters in the documentation. Only crossDomain: true is available out there.
Is Framework7 (Dom7) supports JSONP and callback parameters like jQuery?
I've used the code below without success:
var $$ = Dom7;
$$.ajax({
url: "http://query.yahooapis.com/v1/public/yql",
contentType: "OPTIONS",
crossDomain: true,
data: {
q: "select title,abstract,url from search.news where query=\"cat\"",
format: "json"
},
success: function( response ) {
alert( 'ok' );
alert( response );
}
});

I don't know this way is the best way or not, I had the same problem and this way works for me.
var $$ = Dom7;
$$.ajax({
url: "http://query.yahooapis.com/v1/public/yql",
contentType: "OPTIONS",
dataType : 'json',
crossDomain: true,
data: {
q: "select title,abstract,url from search.news where query=\"cat\"",
format: "json",
callback:function(){
return true;
}
},
success: function( response ) {
alert( 'ok' );
alert( response );
}
});

Related

How to clear a cart's attributes in Shopify?

Previously when I visited /cart/clear or did the below, it cleared my cart, and it's attributes. Now when I do either of those things, it clears the products, but the cart attributes are persisting. I'm not sure if this is a recent change or a Shopify bug?
Any idea how to clear the cart's attributes?
$.ajax({
type: "POST",
url: '/cart/clear.js',
success: function(){
alert('You cleared the cart!');
},
dataType: 'json'
});
I've found a way to delete them all by doing this, which seems overly complicated, but it works.
$.ajax({
type: "GET",
url: '/cart.js',
dataType: 'json',
success: function(resp) {
var nullHash = {};
for ([key, value] of Object.entries(resp.attributes)) {
nullHash[key] = null;
}
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});
}
});
Or if you want to delete them by name, you can do this:
var nullHash = {
'someAtt1': null,
'someAtt2': null,
'someAtt3': null
};
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});

Passing form collection with Knockout.js in asp.net MVC

I am new to MVC and I am trying to create an application with Knockout.js to send data back to the server dynamically. I am following an example i found at:
http://www.mytecbits.com/microsoft/dot-net/knockout-js-and-bootstrap-with-asp-net-mvc-part-2
It works perfectly off the site, but i am trying to send data to multiple models instead just one as in the example
The Knockout code used in the example to send the data back to the server is
var urlPath = window.location.pathname;
var CreateArticleVM = {
Title: ko.observable(),
Excerpts: ko.observable(),
Content: ko.observable(),
Test: ko.observable(),
btnCreateArticle: function() {
$.ajax({
url: urlPath + '/Create',
type: 'post',
dataType: 'json',
data: ko.toJSON(this),
contentType: 'application/json',
success: function(result) {
window.location.href = urlPath + '/';
},
error: function(err) {
if (err.responseText == "success") {
window.location.href = urlPath + '/';
}
else {
alert(err.responseText);
}
},
complete: function() {}
});
}
};
ko.applyBindings(CreateArticleVM);
How do i modify the above code to be able to accept a FormCollection? Or what is the best solution to my problem?
Thanks
Say your service is expecting more than one argument like following.
[HttpPost]
public String Create(ModelA modela, ModelB modelb)
{
//Server code.
}
In order pass the data for Create method from client side you need to form your postdata as follows.
$.ajax({
url: urlPath + '/Create',
type: 'post',
dataType: 'json',
data: {modela: { "modela data in the expected form" }, modelb : { "modelb data.." } },
contentType: 'application/json',
success: function(result) {
window.location.href = urlPath + '/';
},
.
.
.
.
});

sencha touch2 Login examples

I need a cross-domain user login request instance, please help me, thank you!!
My code
Ext.data.JsonP.request({
url: 'http://25.30.2.3:8080/newvbo/applyaction!longin',
params: {
username:'13881901678',
password:'111111',
},
success: function(response, opts) {
alert('1');
},
failure: function(response, opts) {
alert('2');
}
});
My question is, I not receive the server returns the value, I wrong?
You can Try this
Ext.Ajax.request({
method:'GET',
contentType:'application/json; charset=utf-8',
dataType:'json',
url:'http://........Login',
disableCaching: false,
withCredentials: true,
useDefaultXhrHeader: false,
callbackKey: 'callback',
params: {
EmailId:Ext.getCmp('usernametwoway').getValue(),
Password:Ext.getCmp('loginpasswordtwoway').getValue(),
},
success:function(response)
{
console.log(response);
var res = response.responseText;
var jsonarr = Ext.decode(response.responseText);
console.log(jsonarr);
var myres = jsonarr[0].Result;
console.log(myres);
switch(myres)
{
case '1':
console.log("Registration response is successfully");
Ext.Viewport.setActiveItem({xtype:'passengerdetailstwoway'});
break;
case '0':
console.log("Failed");
Ext.Msg.alert("Error","Login Failed",Ext.emptyFn);
break;
Based on the responce you can Specify the Switch case..
Hi #jesse you can try for cross-domain something like this,
Ext.Ajax.request({
url: 'your_url_path',
timeout: 90000,
params: {
withCredentials: true,
useDefaultXhrHeader: false,
username:'13881901678',
password:'111111',
},
success: function(response, o) {
if(response != '') {
alert('1')
}
},
failure: function(response, o) {
alert('2')
}
})
For cross-domain you need put withCredentials: true and useDefaultXhrHeader: false.
I hope help you.
I would like to suggest you a different approach because sending login credentials as GET parameter to remote server over http is not a good idea, instead you should use POST method over HTTPS. Now you would think JSONP doesn't support POST so how can I do this, but if you are going to install your app on Phone or iPad it would do remote call from browser without using JsonP, which means you can use normal AJAX proxy to do whatever you want. Check this out:
How to use json proxy to access remote services during development
Which means this should work:
var obj = new Object();
obj.userId = username;
obj.password = password;
var data = Ext.JSON.encode(obj);
Ext.Ajax.request({
url : 'https://login_url',
method : "POST",
headers: {
'Content-Type': 'application/json'
},
params : data,
useDefaultXhrHeader : false,
withCredentials: true,
success : function(response) {
},
failure : function(response) {
}
});

Not able to change the value of a variable inside the $ajax success

I am having a curiously weird problem, here is my JS code
function ValidateUser(username) {
var userExists = "somevalue";
$.ajax({
contentType: 'application/json, charset=utf-8',
type: "POST",
url: "/Controller/Validate",
data: JSON.stringify({ username: username }),
cache: false,
dataType: "json",
success: function (response) {
alert(response);
if (response == true) {
userExists = true;
alert("user exists: " + userExists);
} else {
alert("user exists: " + userExists);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('error');
}
});
return userExists;
}
well, the action works fine and validates user correctly, but the function ALWAYS returns "somevalue".....What gives? My hunch is that it has something to do with a function scope. But how do I resolve this issue.
Because the function you're calling $.ajax from returns before the Ajax call completes.
The simple answer is to do the work you need to do in the success function, either with an immediate function (as now), or by setting success to an existing function.
You could also use jQuery's $.when function.
You can use the setting "asynch: false" too, it will lock the browser, disabling any actions while the request is active. Here is your code changed:
function ValidateUser(username) {
var userExists = "somevalue";
$.ajax({
contentType: 'application/json, charset=utf-8',
type: "POST",
url: "/Controller/Validate",
asynch: false,
data: JSON.stringify({ username: username }),
cache: false,
dataType: "json",
success: function (response) {
alert(response);
if (response == true) {
userExists = true;
alert("user exists: " + userExists);
} else {
alert("user exists: " + userExists);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('error');
}
});
return userExists;
}
You can get more information here: jQuery.ajax()

what's wrong when using jquery to call wcf service, always return internal server error?

Below is my jquery codes, and it always return internal server error, and i'm sure that my wcf service can be called from i.e and iis.
$.support.cors = true;
$.ajax({
type: "post",
url:"http://localhost:8080/WcfService/FunHeartWork.svc/UpdateMedia",
data: '{"desc":"' + text + '","albumId":"'+albumId+'","mediaId":"'+mediaId+'","userName":"'+userName+'"}',
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (result) {
alert(result);
},
error:function(a,b,c){alert(c);},
failure: function (msg) {
alert(msg);
}
});
Try changing the data line to:
data: {
desc: text,
albumId: albumId,
mediaId: mediaId,
userName: userName
},