get ajax filtered url - ajax

for example i wanna buy laptop. so i go to www.example.com and i go to laptop section. url is : example.com/laptops
and in the filter section i choose asus and the url still is: example.com/laptops
i tried to record what is going on when i hit asus checkbox :
action=filter&filter=2&sort=desc&count=20&menu_name=6&down_price=100&up_price=14790000&groups=&filters_specific=&color=&keyword=&exist=0&special=1
it sends this information to the referer.
i wanna know how to get the url that always lead me to asus laptops in that site.

Pardon my arabic...when you go to the home page and click on the laptop(لپ-تاپ/) section ...the following URL comes
https://www.mobileabi.com/product/لپ-تاپ/
also on the right side the filter appears لپ تاپ و الترابوک
Now from here whenever you check a product ..say acer... an ajax post request fired to the this url
https://www.mobileabi.com/templates/user/modules/sellbasket/ajax.php
you can check it in chrome by pressing F12>Network>XHR
Now each of the brands are given an ID..you could find the group ID by inspect element...
Acer : 216
Lenovo :245
Apple: 251 and so on...
so for e.g. if Acer & Apple are checked in the filter..the URL post params would be groups:216,251 so only... acer & apple laptops would be selected in the post response... you wont see any change in the URL of browser
in order to make the Post into a get Request you gotta change the ajax call at..
$.ajax({
url: "https://www.mobileabi.com/templates/user/modules/search/ajax.php",
data: "action=search"+
"&val="+$(this).val(),
dataType: "html",
cache: false,
context: document.body,
type: "POST",
you have to change the type: "POST", to type: "GET",
similar modification needs to be done on the server side

Related

Shopify app with proxy extension POST requests not working

Following the guide here: https://shopify.dev/tutorials/display-data-on-an-online-store-with-an-application-proxy-app-extension
GET requests are working fine for me.
But when I try to do a POST request, my parameters are not coming through.
I'm building a simple wishlist app, where a user can click on a heart on a product and it adds it to a database.
So my code, when they click the heart, looks something like this:
$.ajax({
url: '/apps/wishlist/save',
type: 'POST',
data: {
shop: shop,
customerId: customerId,
productId: productId
},
dataType: 'json',
success: function (data) {
console.info(data);
}
});
When I inspect this post in Network tab in Chrome Dev Tools, the original POST is hitting a 301, then Shopify is creating a GET request to the original URL with different/missing parameters that look like this:
shop: example.myshopify.com
path_prefix: /apps/wishlist
timestamp: 1585769299
signature: examplesignature
If I change my original AJAX request to a GET, then my original parameters are passed as expected.
Are POST requests not allowed here?
Try to add / to the end of your url i.e. change it to /apps/wishlist/save/.
Just to give a clearification.
Vladimir answer works, why?
It seems that Shopify changed their authentication flow for some POSTs request.
You have to send requests without cookies or you can send requests with X-Shopify-Access-Token header and use your app's password for it. They should work both but there are some cases of use that doesn't permit you to send request without cookie or only uses basic auth (depending on wich method and software you use to send request). Shopify's devs are not crazy of course, this was implemented due to avoid some kind of hackers attack based on specific attacking methods, but maybe it should be better clearly specified in their documentation. Even if the solution explained above should be preferred, as said it could not work in some cases so the Vladimir 's solution is a valid alternative (you could also add a dot at the end of the URL so for example: www.example.com./etc/etc), this because this way "blocks" the cookie seending.
You can know more about that following Sopify's community discussion here

How can I see this .json file in the browser instead of downloading it?

My desired outcome is to get air quality data on my web app.
I'm trying to use the airnowapi API to obtain the data. I use an URL they provided here, but my code fails to retrieve the data.
Here's a sample code of what I'm trying to do.
$.ajax({
url: "http://www.airnowapi.org/aq/observation/latLong/current/?format=application/json&latitude=38.3651&longitude=-114.4141&distance=250&API_KEY=[API-KEY]",
method: 'GET',
dataType: 'jsonp',
success: function(data) {console.log(data);},
error: function(){console.log("fail");}
});
It logs "fail" instead of logging the data. How can I remedy to that?
When I copy-paste the url in my browser, it downloads the .json file correctly, but I was expecting seeing it directly in the browser instead. I'm not sure if this is the origin of the problem.
Thank you!
PS.: This is my first time posting.

jsonp parse to XML

I'm having the following problem.
I'm developing an app with Phonegap, and I have some trouble with the AJAX call on Blackberry.
When I call the ajax service with datatype = 'xml', it works fine on Windows Phone, and Android but failed on Blackberry.
This is the code:
jQuery.ajax({
url: requestedUrl,
dataType: 'xml',
timeout: this.timeout,
beforeSend: _.bind(this.beforeSendCallback, this),
success: _.bind(this.internalSuccessCallback, this),
error: _.bind(this.internalErrorCallback, this),
headers: {'X-Requested-With': 'XMLHttpRequest'}
})
I read on others post, that you cannot do anXMLHttpRequest to an external domain, which is the error that Blackberry shows (but I don't understand why it works on the other two platforms.) So I try to change the dataType to 'jsonp', but a syntaxError shows up. I tried with jsonp text xml, but for some reason it does not and returns the same
Uncaught SyntaxError: Unexpected token <
Looking, the response of the WS, it gave me back a valid XML. So the question is,
How can I use that XML if I'm making the call with jsonp?
EDIT:
Actually, the problem was that the "origin" header was "local:\" (my app), so BB was blocking the content of the response.
The solution was to add that domain to my config.xml, like this:
<access uri="local:///" subdomains="true" />
Unlikely Android and Windows Phone, in the config.xml you have to set access to the domains with uri, not origin and the * wildcard is not allowed with XmlHttpRequest (XHR) on BlackBerry 10.

Absolute/relative address in ajax call in jquerymobile

The following code works fine in iPads and iPhone (4,5) in Safari and Chrome. In contrast, the ajax call won't work (runs straight to the onError function) in Android devices and desktop browsers.
When I exchange the absolute URL for a relative one, the success/failure outcomes are reversed in these two groups.
How do I get around this problem (I'm running jquerymobile 1.3.0 beta)? Thanks/Bruce
$(document).ready(function() {
$("#submit").click(function(){
var formData = $("#loginf").serialize();
$.ajax({
type: "POST",
url: "http://mydomain.org/m2/scripts/site/bpg_process.asp?id=lg",
cache: false,
data: formData,
dataType: 'json',
success: onSuccess,
error: onError
});
return false;
});
});
Do you know that cross-domain Ajax calls are not allowed ?
Your problem may be linked to the URL from which you're making the request, and not to the browser you're testing in.
Read this for more details : http://en.wikipedia.org/wiki/Same_origin_policy
The important thing here for you is that the policy excludes different subdomains.
Ex. if you're sending a request from http://www.mydomain.org to http://mydomain.org it will fail, and vice versa.
What i do in your case usually is use the complete URL "/m2/scripts/site/bpg_process.asp?id=lg" without the protocol and host but with the starting "/" so it can be referenced from anywhere in the URL tree.
What is the "relative URL" that you're using and that "doesn't work"?
Like darma has mentioned. "cross-domain Ajax calls are not allowed".
Use absolute "local" pathing instead.
a slash '/' at the beginning of a link referees to the document root.
if you need to refer to an external domain, use ajax to call a local .asp document that calls the external page for you and returns the data you want in json.
Im not sure what this is in asp but in php, curl works.

jQuery ajax POST from local file to access a cross domain not working

As the title says, I'm trying to access (POST) using jQuery AJAX call to a web url, http://host:port/... or http://localhost:8080/... from a local HTML file, c:\home.html. I can't get it to work.
I did Google and also saw several questions here but I can't get it to work. I need some help here. Here is what I've tried so far.
dataType: jsonp
crossDomain: true
Setting the header in my response:
response.setHeader("Access-Control-Allow-Origin", "*");
None of the three browsers are working - IE, FF or Chrome. The request is never reaching the server. Here are some of the errors I'm seeing.
No Transport (IE) if not jsonp is used.
NS_BINDING_ABORTED / Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED) in FF
This is my code. I would appreciate any help. I'm using jquery-1.8.2.min.js.
var http_host = "http://localhost:8080";
function su (pc, p) {
var suUrl = http_host + "/ps/api/v2/authorize.json";
$.ajax({
type: 'POST',
url: suUrl,
data: {
phone_cell: pc,
password: p,
},
dataType: "json",
crossDomain: true,
success: osu,
error: oe
});
return false;
}
function osu (d) {
console.log(d);
}
function oe(xhr, ts, et) {
alert("ServerError: " + et);
}
An example would be a perfect pointer.
I suppose my code got messed up w/ all the different solutions that I was trying. I was finally able to get it to work w/ setting the header (solution that was recommended and worked for others). All that I had to do to get it to work is add the following to my REST service response.
response.setHeader("Access-Control-Allow-Origin", "*");
Update:
I thought I figured this out but I've not. There is more it than just setting the header. Anyways, in my specific situation. I was trying to run my app (html, js) off of the hard drive specifically on chrome and trying to access web services available on the cloud.
Here is how I finally solved the problem. I started the chrome w/ the following parameters.
--disable-web-security -–allow-file-access-from-files
Like I mentioned earlier, this app is really a desktop application that will be run as part of the chromium embedded framework.
Thanks every one for your input.
You can't make a cross-domain request from a local file because it's not on a domain. You need to host C:\home.html on a local webserver instance in order for it to work.

Resources