简体   繁体   中英

javascript(jquery ajax) in php file

I have a php file in which I have written javscript code. Here is the code

<html>
<head>
<script type="text/javascript"  src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript" src="jquery.cycle.all.js"></script>
<script type="text/javascript"> 
$(document).ready(function() {
alert("Start");
$.ajax({
     type:...
     url:...
     success:function(data, textStatus ){
       alert("Success");
       Jquery Cycle plugin
     }
     error:function(xhr, textStatus, errorThrown){
       alert("Failure");
     }
  });
});

I have a javascript code in php file with extension .php.When I run the above code,php gets executed perfectly.But javascript code is not executing.This I am saying because even the alert() in the first line of script is not getting executed.I am not getting any ajax error or success function printed which is defined in ajax call.

You have missed commas (,) in the ajax function.

It's working at my end with the following changes:

<html>
<head>
<script type="text/javascript"  src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript" src="jquery.cycle.all.js"></script>

<script type="text/javascript"> 
$(document).ready(function() {
alert("Start");
$.ajax({
 type:'GET',
 url:'somepage.php',
 success:function(data, textStatus ){
   alert("Success");

 },
 error:function(xhr, textStatus, errorThrown){
   alert("Failure");
 }
  });
});

 <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { alert("Start"); $.ajax({ type:'GET', url:'somepage.php', success:function(data, textStatus ){ alert("Success"); }, error:function(xhr, textStatus, errorThrown){ alert("Failure"); } }) }); </script> 

Also running on JS Fiddle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM