Hi I am trying to create a button that will call a php function to add products to Shopify from web application
First this is my result.php file which is showing amazon products successfully
http://codepad.org/MPs4y1Qu
There you will find two important things
first <button type="button">add</button>
and
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type: 'POST',
url: 'create_product.php',
success: function(data) {
prompt(data);
}
});
});
});
</script>
The problem is when I click on Add Button it shows the HTML of the page but nothing happens on the create_product.php
file. I want it to call that function. On the other hand my code on create_product
is fine and working 100% separately but not with my web app.
here is my create_product.php
code:
2
Answers
You can add the following ajax function into your script.Note that the ajax function sends a data with value triggerPHP to the page that you have the PHP code. So at the .php page that you run the php code you must set a code to “catch” in someway the triggerPHP data via $_POST[] superglobal and the execute whatever you want.
EG
}
JQuery ajax :
Your AJAX call will send data by POST or GET, then you can do anything with that and also return something to your script. It’s simple like that.
http://api.jquery.com/jquery.ajax/
Let’s work with examples. If you want to make A+B on your server you will need to have a form with inputs like this:
Then you will program some script to say what your form will do on submit. As you’re using jQuery, let’s work with jQuery:
But what’re you doing on the server?
Well, I just want to return my input’s, just to check. Here goes my PHP:
That’s the way you can send information with AJAX to execute something on PHP.