ExtJS - Ajax Call Added to Store From Service Call - ajax

I am new to ExtJS and I am a Flex Developer. I am trying to do a mockup of a page we have in our Flex App. I am trying to do a basic service call to hit our servers (on same domain as the ExtJS App) and add the data into Store, which will then be populated into our dataGrid.
I did the tutorial online, but now I am trying to modify it to use my services from our Flex App. I am able to make the service call, and get a success response; However, it looks like the response is what you get when you paste the URL in your browser (this is a WSDL).
It is not hitting the actual method in the service, and returning data. I did do a simple soapclient.js JS project and was able to get data using that tool, but I do not get data back using Ajax. I think I am doing something simple wrong, but cannot figure it out.
Ext.define('DG.store.PhoneCalls', {
extend: 'Ext.data.Store',
model: 'DG.model.PhoneCall',
autoLoad: true,
proxy: {
type: "ajax",
dataType: 'xml',
contentType: 'text/xml; charset=utf-8',
data: '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Header> <ns0:HeaderID xmlns:ns0="http://urlgoeshere.com/"> <ns0:string>thisisastring</ns0:string> </ns0:HeaderID> </SOAP-ENV:Header> <SOAP-ENV:Body> <tns:getRecaPayments xmlns:tns="http://urlgoeshere.com/"> <arg0>false</arg0> </tns:getRecaPayments> </SOAP-ENV:Body></SOAP-ENV:Envelope>',
url: "https://urlgoeshere.com.com/Payments_UISupport_HTTPRouter/RecaCompFacadeService/RecaCompFacadeService.wsdl",
reader: {
type: 'xml',
root: 'return',
record: 'contents'
},
afterRequest:function(req, res) {
console.log("Result: " + req.operation.response);
}
}
});
When I debug, this is not hitting the method for this service. It returns the entire WSDL response that shows all of the methods available for that service.
In Flex, I have no issue. This app is on the same domain, so that is not the issue. I tried using soap in ExtJS and it didn't work either. I am sure it is a user error here! =)
All I need to do is:
Call this service: https://urlgoeshere.com.com/Payments_UISupport_HTTPRouter/RecaCompFacadeService/RecaCompFacadeService.wsdl
Pass in a false boolean
Hit this method within that service: getRecaPayments
This service returns a bunch of data like this:
<return>
<contents>
<name>Joe</name>
<ssn>111112222</ssn>
</contents>
<contents>
<name>Bob</name>
<ssn>222342222</ssn>
</contents>
<contents>
<name>Jan</name>
<ssn>555443333</ssn>
</contents>
</return>
Here is my model PhoneCall:
Ext.define('DG.model.PhoneCall', {
extend: 'Ext.data.Model',
fields: ['name', 'ssn']
});

Just did some research - and found the two required SOAP classes within the docs.
These files are indeed not contained within the src/data/soap directory...
http://docs.sencha.com/extjs/4.2.2/source/Proxy3.html
http://docs.sencha.com/extjs/4.2.2/source/Reader3.html#Ext-data-soap-Reader
Here it's explained in detail, better than I ever could:
http://docs.sencha.com/extjs/4.2.2/#/guide/soap

Related

Shopify order API returns OK but does not update order using JS

I'm trying to create an order using JS. I've authenticated my app and have a function that POST's to orders.json. I see a status code of 200, indicating that the request submitted OK (right?) but the order itself never gets created. I've heard something about disabling cookies in my request, but I don't know how to do that, so if that's what I need to do please let me know.
I'm putting up my entire function, since I'm new to this entire thing and it seems that it's probably the structure of my request, not the API call. I'm seeing the "Error" log in the console, so clearly the error function is running.
function submitShuffle(prodid)
{
console.log(prodid);
var params = {
"order": {
"line_items": [
{
"variant_id": prodid,
"quantity": 1
}
]
}
};
$.ajax({
type: 'POST',
url: 'https://<my-usrnam>:<my-pass>#toyboxshufflesandbox.myshopify.com/admin/orders.json',
dataType: 'application/json',
data: params,
success: function(data){
console.log(data);
},
error: function(data){
console.log("Error");
console.log(data);}
});
}
You cannot retrieve information from Shopify Admin API by AJAX. There is a limitation about this because you have to expose your username/key and password which is not a good idea.
You have to use some service/app or just to create a custom app.
Shopify returns an Object when you make a call. Hence 200 OK status. Inspect the object returned. A failed create POST object will not have an ID. So there is clue number one. Secondly, you'll see that Shopify tells you what the problem was in the Error key of the returned object. If you cannot figure out what you did with the message from Shopify, make the same call to the GraphQL endpoint if you can, as the error messages Shopify returns from those endpoints are currently much better. They are backporting them to the older REST API, but for now, GraphQL is more expressive.

AJAX explained in detail

I found allot of examples of AJAX and I think I can get some code with it to work on my own. If only I knew what the use of all the terms of the AJAX code where.
I think in general it lacks the availability of these guides or special pages where constructed code is explained in detail for new programmers.
This would help enormously because of the misunderstanding of the syntax in many cases. Me for example spend 8 hours a day on my internship to learn PHP, Jquery, HTML from scratch and there is allot of information out there but its not structured and in most cases to technical. Any tips on that maby ? :)
$.ajax({
type: 'POST',
url: 'http://kyleschaeffer.com/feed/',
data: { postVar1: 'theValue1', postVar2: 'theValue2' },
beforeSend:function(){
// this is where we append a loading image
$('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>');
},
success:function(data){
// successful request; do something with the data
$('#ajax-panel').empty();
$(data).find('item').each(function(i){
$('#ajax-panel').append('<h4>' + $(this).find('title').text() + '</h4><p>' + $(this).find('link').text() + '</p>');
});
},
error:function(){
// failed request; give feedback to user
$('#ajax-panel').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
}
});
Ajax is asynchronous, which mean you can use it to get new informations from the server without reloading the whole page.
Here's an explanation of your code :
$.ajax({
$ is the JQuery object, on which you're calling the ajax function
type: 'POST',
You're gonna send your data by post, which mean that you'll have to get them in php with $_POST['variable_name']. You could also put GET instead
url: 'http://kyleschaeffer.com/feed/',
the url you want to reach
data: { postVar1: 'theValue1', postVar2: 'theValue2' },
as you're sending your request with POST, you cannot pass data directly from the URL.
So you have to pass them like that. { nameVar: 'value', .... }
If you were sending with GET, you could directly write them into url like : "http://my_url.php?var1=val1&var2=val2 etc ...
beforeSend:function()
You can define an action before sending your ajax request
$('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>');
Here, inside your div "ajax-panel" you want to write some content. (a div "loading" and a picture inside "loading").
success:function(data)
If your request is successful, you can do something. By successful it means if server answer 200 i guess, anyway ... If you have a response from server... ;)
$('#ajax-panel').empty();
You delete content into ajax-panel
$(data).find('item').each(function(i){
$('#ajax-panel').append('<h4>' + $(this).find('title').text() + '</h4><p>' + $(this).find('link').text() + '</p>');
});
You're adding some html AFTER (append) the ajax-panel div
error:function()
Not sure you were looking for that, hope that help you ;)
AJAX is an acronym standing for Asynchronous JavaScript and XML and this technology help us to load data from the server without a browser page refresh.
If you are new with AJAX, I would recommend you go through our Ajax Tutorial before proceeding further.
JQuery is a great tool which provides a rich set of AJAX methods to develope next generation web application
Take a took at this
$.ajax({
type : varType, //GET or POST or PUT or DELETE verb
url : varUrl, // Location of the service
data : varData, //Data sent to server
contentType : varContentType, // content type sent to server
dataType : varDataType, //Expected data format from server
processdata : varProcessData, //True or False
success : function(msg) {//On Successfull service call
},
error : function() {// When Service call fails
}
});

Using periods in parameter name using Ext JS Model load method

Using Ext-JS 4.1 with Spring 3.1 Controllers.
I am trying to retrieve an object from my Spring Controller using the load() method. I read a string from a text field and send that into the load method. The string field will contain a fully qualified server name such as "company.server.com". What's happening is that the value within the Spring controllers is "company.server", in other words it drops the ".com". It I put in an additional period at the end such as "company.server.com." then it comes in properly as "company.server.com". There seems to be some sort of tokenizing going on. I used commas (,) just to see what would happen. Using commas the string came in as expected. For some reason periods (.) is causing the issue.
Here is the Model:
Ext.define('AB.model.Server', {
extend: 'Ext.data.Model',
fields: [
{name:'serverName', type:'String'},
{name:'memory', type:'String'},
{name:'cpus', type:'int'}
],
proxy {
type: 'rest',
url: '/web/user/'
}
});
Here is a snippet from the form which makes the load() call:
Ext.define('AB.view.Form', {
extend: 'Ext.form.Panel',
....
,{
xtype: 'button',
text: 'Retrieve Information',
handler: function() {
Ext.ModelManager.getModel('AB.model.User').load(Ext.getCmp('serverName').getValue(), {
success: function(user) {
alert("Success");
}
....
}
Using Firebug I see this as the URL being called:
http://myServer/web/user/company.server.com?_dc=13461612333647?id=company.server.com
So the URL has the correct server name but on the Spring Controller side the value of my parameter is "company.server".
When I directly put the following URL directly in my web browser:
http://myServer/web/user/company.server.com/
it works properly with the parameter in the Spring Controller being "company.server.com".
Is this an EXT JS problem? Is a problem with EXT JS to Spring? I don't think it is a Spring issue alone since the URL directly in the browser works properly.
UPDATE:
When I put the following URL directly in my web browser:
http://myServer/web/user/company.server.com
it behaves the same as the EXT JS Rest call. Notice there is no ending slash (/). So maybe this is a Spring issue? Or maybe a web.xml issue?

sencha touch - ajax call to server (url , extra parameter formation)

I am using this to get the result from server
controller.allVisitStore = new Ext.data.Store({
model: 'allVisit',
autoLoad : true,
proxy: {
type: 'ajax',
id: 'allvisit_app_localstore',
url: '/RadMobApp/api',
extraParams:{
action:'query',
queryName:'GET_ALL_VISIT',
authToken: localStorage.getItem("auth_token"),
patTicketId: localStorage.getItem("patientId"),
retFormat:'XML',
keyValuePair:'yes'
},
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "T4" tag
record: 'data'
})
}
});
but i am not getting any thing.But i formed this url in browser and checked this i got the correct result. now here i want to check is there any problem in the url formation.How to check the url formation with extra parameter which is pass through ajax. I have checked in Inspect element-> network -> api there is no any api request found there.Is anything wrong in my code. Thanks in advance...
Use Firebug for Firefox or Chrome's developer tools to see what's going on when that store attempts to load itself. My hunch is that your url is incorrect and should be url: '/api' because RadMobApp is probably your app root.

Sencha Error XMLHttpRequest cannot load http://localhost.... Origin null is not allowed by Access-Control-Allow-Origin

I'm having a problem with loading a Sencha store. My store declaration is like this:
Ext.regModel('Car',{
idProperty: 'id',
fields: [
//'id', 'company', 'driver', 'carType','xCoordinate','yCoordinate'
{name: 'id', type: 'int'},
{name:'company', type:'string'} ,
{name:'driver', type:'string'},
{name:'carType', type:'string'},
{name:'xCoordinate', type:'int'},
{name:'yCoordinate', type:'int'}
]
});
var strr= new Ext.regStore({
id:'carStore',
model:'Car', //configuration option is the cars
proxy: {
type: 'ajax',
url: 'http://localhost:8080/A/carStore.html&callback=?',
reader: {
type: 'json',
root: 'carss'
},
},
autoLoad: true
});
And I'm keeping the store in a list:
CarManagementSystem.views.carList = new Ext.List({
id: 'carList',
store: 'carStore',
onItemDisclosure: function (record) {
var selectedCar = record;
CarManagementSystem.views.addNewCar.load(selectedCar);
CarManagementSystem.views.viewport.setActiveItem('addNewCar', { type: 'slide', direction: 'left' });
},
itemTpl: '<div class="list-item-id">{id}</div>' +'<div class="list-item-driver">{driver}</div>'
});
However, when I try to load the list with my JSON file, I get this error:
XMLHttpRequest cannot load http://localhost:8080/A/carStore.html&callback=?&_dc=1311751412006&limit=25. Origin null is not allowed by Access-Control-Allow-Origin.
sencha-touch-debug.js:7212
Uncaught TypeError: Cannot read property 'length' of undefined
I'm keeping my JSON file in an html format and it is kept in the server. I'd appreciate any help.
Thanks!
You are encountering the classic CORS issue.
It's a browser security, called web-security. If you are in dev mode, you can run Chrome and disabling this flag. But if you run your app in production on a browser, you will need to bypass this ajax specification restriction.
To bypass it, you can use proxys (such as creating a back-end script on the same domain will load for you the resource) or you can use JSON-P. For this you will need to change your store to a script tag BUT ALSO you will need the server to be able to detect a callback param and send it to you as a JS function automatically executed when inserted in the DOM.
I will add that you won't have this issue when running in Phonegap because PhoneGap is not running a web server but serves files with the file:// protocol.
If you want to learn more, and I recommand as it is a common pb when developing mobile web apps, you should learn what JSON-P is, what CORS is, and how it works.
You can't hit a port number (8080) when making an AJAX request. If you end up needing a cross-domain request change your proxy type to 'scripttag'.
You should change the proxy type from 'ajax' to 'type: 'scripttag'

Resources