PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old November 1st, 2012, 11:15 AM
shile shile is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 12 shile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 24 sec
Reputation Power: 0
Calling a php script from javascript onclick

i want to execute a php script when i click on a button in html generated by javascript,i was trying with jquery ajax and i did this but nothing happens...any help pls?the php script is working so its not that,i guess i am missing something in this ajax call..

Code:
$(".formBtn").click(function(){          $.ajax({         url: "script to call",         type: "post",                  // callback handler that will be called on success         success: function(response, textStatus, jqXHR){             // log a message to the console             console.log("Hooray, it worked!");             alert("Working!");         },         // callback handler that will be called on error         error: function(jqXHR, textStatus, errorThrown){             // log the error to the console             console.log(                 "The following error occured: "+                 textStatus, errorThrown             );         },         // callback handler that will be called on completion         // which means, either on success or error         complete: function(){             // enable the inputs             $inputs.removeAttr("disabled");         }     });        });


and this is the php script

PHP Code:
 $api_key 'apikey';     $project_id 'projectid';     $phone_id 'phoneid';         $to_number 'number';     $content 'content';               $curl curl_init();     curl_setopt($curlCURLOPT_URL,          "urlblblbll");     curl_setopt($curlCURLOPT_USERPWD"{$api_key}:");       curl_setopt($curlCURLOPT_RETURNTRANSFER1);     curl_setopt($curlCURLOPT_POSTFIELDShttp_build_query(array(         'content' => $content,         'phone_id' => $phone_id,         'to_number' => $to_number,              )));                           $json curl_exec($curl);         if ($err curl_error($curl)) { echo "$err\n"; }         curl_close($curl);              $res json_decode($jsontrue);                  var_dump($res); // do something with $res     } 

Reply With Quote
Old November 2nd, 2012, 10:10 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
Are you getting any errors? have you tried running the php on its own?
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Reply With Quote
Old November 2nd, 2012, 01:03 PM
shile shile is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 12 shile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 24 sec
Reputation Power: 0
yes i have,and it works fine...

Reply With Quote
Old November 3rd, 2012, 07:22 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
you need to provide a bit more information, ie exactly what you are doing, what you are expecting... posting 2 bits of code formatted terribly is hard to trouble shoot.

Reply With Quote
Old November 3rd, 2012, 07:47 AM
shile shile is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 12 shile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 24 sec
Reputation Power: 0
this php script sends sms message and i want when a button is clicked to send that message,but the problem is that button is already linked with a submit form so i have to do this with ajax...

Reply With Quote
Old November 4th, 2012, 01:31 PM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
In your ajax, i dont see where you passing the post variables?

Reply With Quote
Old November 4th, 2012, 02:38 PM
Sleeping Troll Sleeping Troll is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Sleeping Troll User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 6 m 20 sec
Reputation Power: 0
Only one click allowed!

If the button is type = "submit" that is all you will get! only one click event procedure will be called and that will be the submit.

You should not need a submit form and an ajax script... (actually you can't have both) handle the whole thing with ajax!

Reply With Quote
Old November 5th, 2012, 04:39 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
Quote:
Originally Posted by Sleeping Troll
If the button is type = "submit" that is all you will get! only one click event procedure will be called and that will be the submit.

You should not need a submit form and an ajax script... (actually you can't have both) handle the whole thing with ajax!


if there is no need for a form submission, type="button" would be better as it will not submit the form.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Calling a php script from javascript onclick


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap