I have a jquery-ajax function that sends data to a php script and the problem is with the return value, it returns the whole page instead of single value.
Thank you for your time and help.
$("#ajaxBtn").click(function(){ var inputText = $("#testText").val(); $.ajax({ type: "POST", url: "index.php", data: "testAjax="+inputText, dataType: "html", success: function(html){ alert(html); } }); });
The jqXHR Object. The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.
The ajax() method in jQuery is used to perform an AJAX request or asynchronous HTTP request. Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.
ajax() method allows you to send asynchronous http requests to submit or retrieve data from the server without reloading the whole page. $. ajax() can be used to send http GET, POST, PUT, DELETE etc.
dataType The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response. "text": A plain text string. So you want contentType to be application/json and dataType to be text : $.
That's how it works. You're requesting index.php
via AJAX, so you'll get whatever the contents of index.php
are.
If you want a particular value, make a new PHP page that outputs just that value, and request that URL's contents instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With