Trying to pass variable values from JavaScript to PHP using AJAX

后端 未结 2 1776
天命终不由人
天命终不由人 2020-12-05 06:01

I want to pass some values from JavaScript to PHP using jQuery/AJAX. I have the following \"simplified\" code, not sure what is that I am doing wrong. There seems to be quit

2条回答
  •  [愿得一人]
    2020-12-05 06:46

    $("#text-id").click(function(e) {// because #text-id is an anchor tag so stop its default behaivour
    e.preventDefault();
    $.ajax({
    type: "POST",// see also here
    url: 'text.php',// and this path will be proper
    data: {
           source1: "some text",
           source2: "some text 2"}
    }).done(function( msg )
          {
           alert( "Data Saved: " + msg );// see alert is come or not
         });
    });
    

    reference ajax

提交回复
热议问题