mardi 30 octobre 2018

Ember Adapter Receive Data via Ajax Post

I am new to Ember and this is my first question on stackoverflow. I am working on client side of an Ember project and I need to pull JSON data from a Rest Api. Previously I could extract data given as below:

//app\adapters\product.js

export default DS.RESTAdapter.extend({

host:"http://10.1.7.13,
pathForType(){
 return "content.php?method=list&pr1=product&pr2=all&uname=aaa&upass=1234";    }});

// app\serializers\product.js

export default DS.RESTSerializer.extend({

normalizeResponse (store, primaryModelClass, payload, id, requestType){

payload={
    products:payload
};
return this._super(store,primaryModelClass, payload, id, requestType)

} });

Then the url for backend changed and now username and userpassword are not params for url but send in as form data.

In the new form the url for list products is "http://10.1.7.13/content.php?method=list&pr1=product&pr2=all"

Although if I just access with this url page gives warning as username and userpassword is not defined. So I cant reach json data.

But if I send an ajax post request as below

 $.ajax({

    type:"POST",

    url: "http://10.1.7.13/content.php?method=list&pr1=product&pr2=all",

    data: {
    "uname":"aaa",
    "upass":1234
    },

    success: function(response){

    console.log(response);
    }
});

I can see my JSON data as I have given username and password as form data. My question is where can I call this ajax post and how can I load the response to product model? Ideally I want to call on adapter and send response to serializer then add that to my model like before. But I looked into adapter methods and did not see one that helps me. I am new to rest api so could you tell me what should I do?




Aucun commentaire:

Enregistrer un commentaire