I've been trying the code at: https://gist.github.com/Exeu/4674423 this is a code that connects to amazon wsdl and retrieve product information. so far I have not been able to make it work. The code consist of a index.html, ama_funtion.js, search.php, AmazonECS.class.php. The index file loads and you insert the item name you want choose the category and other params, then when you click in the search link it goes to the ama_function.js and it make and ajax request to the search.php which have the passwords and keys to connect to the wsld, then it request the info from Amazon and return it as JSON to ama_function.js.
I have test ama_funtions.js to see if the index.html file connects to it, and it does, I did put an alert to show the input in the search box at index.html. Also I have test the search.php, I have manualy put the values in the search.php file and it connects to amazon and retrieve the product information as JSON object. the problem is that there is not a success callback as no data return to ama_funtions.js from search.php to be rendered. I know this as I tested it by adding an error function
$.ajax({
url: "search.php",
dataType: 'json',
type: 'GET',
error: function () {
alert("NO DATA");
},
and it did show me the alert, also I have tried to change the ->
data: "q="+value+"&category="+cat+"&country="+country+"&page="+page,
for ->
data: {
q : value,
category : cat,
country : country,
page : page }
nothing works I am crazy looking to solve this, I will appreciate someone that help us with this. Please see a working example which belong the person sharing the code -> http://amazonecs.pixel-web.org. This is the way is suppose to work but it doesn't.
Regards
$.ajax({
url: "search.php",
dataType: 'json',
type: 'GET',
error: function () {
alert("NO DATA");
},
data: "q="+value+"&category="+cat+"&country="+country+"&page="+page,
data: {
q : value,
category : cat,
country : country,
page : page
}
})
Related
I'm not the best to explain problems but i'll try my best.
So i'm developping a website with php and javascript and bootstrap.
I got a list of equipment that i want to be able to edit with a modal form.
What i'm doing is that i write the id of the equipment (from mysql) into the id of the picture that i'm supposed to click to edit the equipment.
Like this
When i'm clicking on it it goes to a JS page that execute an ajax request to get all the infos from the database.
Now the main problem: when i transfer the id with the ajax request (with $_POST) and i var_dump it to see if i really have it it shows like that: Array ( [1] => )
The number is actually the ID but i have no idea how to use it as a string to get my infos.
If I get you right, your question is "How can I fix the ajax request to process it in PHP?"
Without seeing the specific code-part that you need help with, it's difficult to tell what exactly needs to be changed.
From your description, I assume that your Ajax request in JS looks like this
// your code is either this:
jQuery.post( 'https://example.org?' + id );
// or this:
jQuery.post( 'https://example.org', id );
This will give you the URL https://example.org?1, which is equal to the URL https://example.org?1= (i.e., param "1" is an empty string)
You need to give the ID a param name. Like this:
// This will work (add the string before the parameter value "id=")
jQuery.post( 'https://example.org?item=' + id );
// This is even better - set the post data as object:
jQuery.post( 'https://example.org', { 'item': id } );
In PHP you can then access the product id via $_POST['item'].
Of course, you can use any other param instead of "item" and even pass multiple values inside the post object.
Update based on new comment
The problem is, that you only pass the ID to the post-request, without assigning a name to it: data: id
Change this to data: {item: id} and you have $_POST['item'] in PHP. Here's the full code:
$.ajax({
url: "getInfos.php",
type: "POST",
data: {item: id}, // <-- change this line!
success:function(response){
$('#bodyEdit').html(response);
$('#myModalEdit').modal('show');
},
error:function (resultat, statut, erreur){
console.log(resultat, statut, erreur );
}
})
EDIT: the answer above works better, it seems i've got more than one problem for this issue and the answer above helped me correct it for good
thanks to everyone that answers my question,
i found out about the problem.
First i was the ajax function built in jquery:
$.ajax({
url: "getInfos.php",
type: "POST",
data: {item: id}, // <-- change this line! credit to Philipp
success:function(response){
$('#bodyEdit').html(response);
$('#myModalEdit').modal('show');
},
error:function (resultat, statut, erreur){
console.log(resultat, statut, erreur );
}
});
I was sending the id with data: but the value was missing .serialize after it, wich adapt the value to the url query if i understood correctly.
working code:
$.ajax({
url: "getInfos.php",
type: "POST",
data: id.serialize(),
success:function(response){
$('#bodyEdit').html(response);
$('#myModalEdit').modal('show');
},
error:function (resultat, statut, erreur){
console.log(resultat, statut, erreur );
}
});
I have an Opencart website, I am currently trying to use ajax at the frontend to pass data to php controller in the backend, but I am unable to get the value from the request in backend
here is the frontend ajax code:
$.ajax({ url: 'index.php?route=checkout/cart/addAll',
type: 'post',
data: 'product_list= test' ,
dataType: 'json',
success: function(json) {});
at the backend controller, I am trying to retrieve variable "product_list" but it is not working
$products = $this->request->post['product_list'];
$logger->write("products to add to cart is"+ strval($products));
the last statement keeps printing 0 to the log file
any help with this ? what is wrong here?
I also tried
$products = json_decode($this->request->post['product_list'], true);
with same results
Ok, fixed, Ajax was not the issue, it was accessing the variable from server side, so I used $_POST
instead of $this->request->post and it is working fine
So I just did this
in file catalog/view/theme/defaulttemplate/common/home.twig I add this code at the end of the file
$(document).ready(function() {
$.ajax({url:'index.php?route=checkout/cart/addAll',
type: 'post',
data: 'product_list= test' ,
dataType: 'json',
success: function(json) {}
});
});
and in file catalog/controller/checkout/cart.php on line 479 I add this
public function addAll(){
print_r($this->request->post);
}
And I see this in my console http://joxi.ru/krDlvPdfKGejar
All I did was correct your js code. hope this helps.
I'm trying to create a simple "Register your interest" action. I have the front end working but I'm not sure how to link the AJAX to the PHP file. Where do I put the PHP file?
My current code for the AJAX is:
$.ajax({
url: "register-interest.php",
type: "GET",
dataType: "json",
data: {
type : "registerInterest",
email : userEmailLog,
user : userNameLog,
product : productTitle,
sku : productSku
},
success: function (response) {
JSON.stringify(response);
},
error: function (err) {
JSON.stringify(err);
},
complete : function() {
//$('.user-accept').addClass('unhide');
loading();
}
});
First you check url variable is correct or not and then provide response any data like
success: function (response) {
JSON.stringify(response);
},
Your url value is:
"register-interest.php"
This implies that the php file that processes the AJAX request needs to be available at the same directory level as the page that includes the javascript file that is performing the AJAX request.
Example:
If your page is at http://example.com/my/ajax/page.html
Then the javascript will perform the AJAX request to the URL http://example.com/my/ajax/register-interest.php
Alternatively if you change the JS url value to read "/register-interest.php", then the AJAX request will be made to: http://example.com/register-interest.php
Where you need to put it on your server depends on how your web server's webroot's folder structure is organised, but you should be able to work back from the URL the javascript will be requesting to work this out.
Hello im trying to upload a xlsx file one by one so i can show a status bar, the problem is, i did it with a for loop and while loop sending a request via ajax, but when is on the 40th element it stops and the console shows POST (site.php) net::ERR_EMPTY_RESPONSE, i tried to do it in the localhost and it works perfect, but when a i try to do it on my external server(godaddy) it shows the error. here is the code.
for(j=1;j<=tama;j++){
$.ajax({
type: "POST",
url: "ejphp.php",
dataType: "json",
data: {vals: regs, j:j},
success: function(datos){
console.log(j)
prog=datos['progreso_r'];
var id_vac=datos['id_vac']
var tipo=datos['tipo']
var tipo2=datos['tipo2']
var tot_ing=datos['tot_ing']
prog_p=Math.round(prog*100/tama);
$("#progressbar").val(prog_p);
$("#progreso").text(prog_p+'%');
$("#datos_vac").text('Id Vacuno: '+id_vac);
if(prog_p==100){
$("#aceptar").show("slow");
}
if(tipo=='error') registro(tipo2, id_vac)
subir(parseInt(prog)+1);
return false;
}
})
}
Maybe your server can't pass more than 40 requests, try to increase php memory limit and execution time. And try to browse in godaddy's admin panel.
I am using Wordpress Shopping cart. I want to append or modify the product name based on 3 variations the same thing goes for the price to.
I have tried to implement a simple Jquery on click event to an image using the AJAX $.post method within the single product page. It's not sending the data value even if I encode it with JSON. I must say that I'm new with JSON and PHP. Thanks in advance !
In the single product page
$(function() {
$('#div_img_link').click(function() {
$.ajax({
type: 'POST',
data: "test value",
// dataType : "json",
url: '../wpsc-cart_widget.php',
cache:false
});
});
});
In wpsc-cart_widget.php
$name=wpsc_cart_item_name();
if (isset($_POST['data'])){
$value1 = $_POST['data'];
}else{
$value1 = "";
}
echo "$name $value1";
I know that are some similar posts out there I've read them all can't figure it out. I want to know if the WPSC can perform the jQuery POST function without refreshing the page. Any help will be greatly appreciated!!
schematics
EDIT
SCHEMATICS 2 - to be more concise !
What I'm trying to accomplish
SEA, you're missing a function to handle the response that comes back from the server.
I would expect to see something like this :
$(function() {
$('#div_img_link').click(function() {
$.ajax({
url: '../wpsc-cart_widget.php',
type: 'POST',
data: "test value",
dataType : "JSON",
cache:false,
success: function(data) {
//do something here with the data.
//eg.
alert(data);
},
error: function() {
//do something here if an error occurs.
//eg.
alert("an error occurred");
},
});
});
});
The best place to learn more about ajax is the ajax() page in the jQuery API documentation.
You also need to ensure that the server response and the client expectation are compatible. With a client expectation of dataType: "JSON", you must ensure that the server returns a json-encoded response. Json-encoding is only necessary for multiple data in a single response. A single data item can be sent unencoded.
EDIT:
After seeing your Schematic 2, I think your ajax request data should look something like this :
data: {
'pid': '12345678',
'quantity': '1'
),
where pid is the "product id" and quantity is how many of the product the user wants to add to his/her basket.
But surely the WPSC documentation includes examples of this stuff? You shouldn't have to work it out for yourself.